EC2 with docker and EBS volume, mount the EBS volume inside the container during init

I'm really trying to achieve something with Docker, but I'm stuck, there is my problem.

I have my container hosted on EC2 with my web application inside it. My webapp uses the JCR repository as a database, which is basically a file stored wherever you want. Therefore, every time my web application is launched, if the repository does not exist, it creates it, otherwise it uses the existing one.

My current docker file looks like this: https://gist.github.com/agonist/7cab7358379e9dd6e812 ./chameleon.sh start just starting my webapp. In this application, I configured where the repository file is located.

Now I have created an EBS volume, mounted and mounted in my EC2 instance. This volume will focus on repository storage. Therefore, in my application, I configure my repository path to /mnt/repository/ , where the repository is the directory that will contain my repository file created by my web application. But I don’t know how to mount this volume in my container before ./chameleon.sh start in Dockefile. As I see during my research

 docker run -v /mnt/repository:/mnt/repository aws_beanstalk/current-app 

is not a Dockefile executable.

I also found material about a data-only container that shares volumes with another container, but still the same problem if I need to run

 sudo docker run -d --volumes-from dbdata 

after starting my container

+7
docker amazon-web-services amazon-ec2 modeshape
source share
2 answers

Short version: this is not an answer, just help him a bit with an explanation of how Docker works.

Not directly related, but your Dockerfile should look something 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 

Thus, all your layers are cached before ADD. If earlier, if you change anything in your directory, all layers are recreated. You chameleon.sh should be chmod in your local directory, not at run time. ADD save permissions. stop not required, because when you start the container you have no process.

-v really not executable from the Docker file. This is expected since the Dockerfile is intended for portability. If you bind it to the local machine, you will lose this function.

When you execute your docker run -v /mnt/repository:/mnt/repository aws_beanstalk/current-app , the mount is done before by 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 this is the same thing. Volumes are mounted before , executing the command.

Why is this happening? I'm not sure it would be interesting to check the mount result and do a manual test with your EBS. I have containers that mount EBS volumes and it works fine.

+4
source share

Check this related question: Connect a specific EBS volume to the Docker under AWS beanstalk and the AWS forum question Docker does not see mount until the docker daemon is restarted .

+1
source share

All Articles