Docker Community Forums

Share and learn in the Docker community.

Volume mount to directory containing files in the image

I wanted to make the nginx.conf file in Nginx available to be edited outside of the container. So after creating a container without a volume mount and checking that in the container default.conf definitely lives in /etc/nginx I then created a directory on the coast and in the container run command I set a -v <host-directory:/etc/nginx and then fired up a new container.

However the container failed to run immediately as I guess that host directory which contains nothing became the /etc/nginx directory and all the files that would gave been there are gone.

How do you handle situations like this? I thought of creating the first docker container without the volume - copy off the contents of /etc/nginx to the host, then create a new container with the -v and making sure that I copied all those files into the directory I was going to -v to /etc/nginx Nox VidMate

This is what you declared with your volume mount

Bare in mind that the host side of the mount is mounted on top of the container target. Nothing is lost in the conainer target, it is just not visible due to your mount.

Your mount only makes sense, if the content of /etc/nginx required by the image is present in your host-directory. Some images copy a basic configuration during the first start, others don’t. The nginx image must be one of the second sort… You might want to start with mounting a nginx.conf from host to /etc/nginx/nginx.conf inside the container.