I actually trying to achieve something with Docker but I'm stuck, there is my problem.
I have my container hosted on EC2 with my web app inside it. My webapp use as database a JCR repository which is basically a file stored where you want. So each time my web app start, if the repository doesn't exist, it create it otherwise it use the existing.
My current docker file look like this https://gist.github.com/agonist/7cab7358379e9dd6e812 ./chameleon.sh start just start my webapp. In this app, I configured where the repository file is located.
Now I creted a EBS volume attached and mounted in my EC2 instance. This volume will be dedicated to store the repository. So basicaly in my app I configure my repository path to /mnt/repository/
where repository is the directory which will contain my repository file created by my web app.
But I don't know how I can mount this volume to my container before the ./chameleon.sh start
in the Dockefile. As I see during my research
docker run -v /mnt/repository:/mnt/repository aws_beanstalk/current-app
is not executable from the Dockefile.
I also found stuff about data only container which share a volume with another container, but still the same probleme if I have to run
sudo docker run -d --volumes-from dbdata
after my container started
launch the ECS Service for our ECS Task, which will deploy to one of our EC2 instances. connect to our Postgres container, and create some data in a new database. move the ECS Task from one EC2 instance to the other, which will restart the task. connect to Postgres again, and see that data has persisted.
To attach an EBS volume to an instance using the consoleOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic Block Store, Volumes. Select an available volume and choose Actions, Attach Volume. For Instance, start typing the name or ID of the instance.
You can attach multiple EBS volumes to a single instance. The volume and instance must be in the same Availability Zone. Depending on the volume and instance types, you can use Multi-Attach to mount a volume to multiple instances at the same time.
You specify the EBS volumes and instance store volumes for your instance using a block device mapping. Each entry in a block device mapping includes a device name and the volume that it maps to. The default block device mapping is specified by the AMI you use.
Short version: This is not an answer, just a little help towards it with clarification on how Docker works.
Not directly related, but your Dockerfile should probably look like this:
FROM dockerfile/java:oracle-java8
# Expose the port 9000
EXPOSE 9000
# Volumes
VOLUME /root/wisdom/logs
VOLUME /root/wisdom/application
# Change workdir.
WORKDIR /root/wisdom
RUN touch /root/wisdom.log
# Add the wisdom distribution
ADD . /root/wisdom
# For easier handling, we dump the log, so `docker logs containerId` displays
# the log.
CMD ./chameleon.sh start && tail -F logs/wisdom.log
That way, all your layers before ADD are cached. Whereas before, if you change anything in your directory, all the layers are recreated.
You chameleon.sh
should be chmod on your local directory, not at runtime. ADD
conserve permissions.
the stop
is not necessary as when you start your container, you have no process running.
The -v
is indeed not executable from a Dockerfile. This is expected as Dockerfile are meant to be portable. If you tie it to your local machine, then you lose this feature.
When you do your docker run -v /mnt/repository:/mnt/repository aws_beanstalk/current-app
, the mount is done before executing the command. You can double check this by running docker run -v /mnt/repository:/mnt/repository aws_beanstalk/current-app mount
When using --volumes-from
, it is the same thing. The volumes are mounted before executing the command.
Why then does it fail? I am unsure, it would be interesting to inspect the mount
result and do some manual testing with your EBS. I have some containers mounting EBS volumes and it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With