Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 with Docker and EBS volume, mount EBS volume inside container during init

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

like image 518
agonist_ Avatar asked Nov 20 '14 14:11

agonist_


People also ask

How do I mount EBS volume on Docker container?

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.

How do you attach and mount EBS volume to EC2 instance?

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.

Can you attach an EBS volume to more than EC2 instance at the same time?

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.

Can you attach volume to AWS EC2 instance?

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.


1 Answers

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.

like image 189
creack Avatar answered Sep 16 '22 15:09

creack