Docker - it is not possible to mount the volume on top of an existing file, the file exists

I am trying to create a data container for my application in Docker. I run this command to expose some volumes:

docker run --name svenv.nl-data -v /etc/environment -v /etc/ssl/certs -v /var/lib/mysql -d svenv/svenv.nl-data 

The problem is that I get this error from this command:

 Error response from daemon: cannot mount volume over existing file, file exists /var/lib/docker/aufs/mnt/aefa66cf55357e2e1e4f84c2d4d2d03fa2375c8900fe3c0e1e6bc02f13e54d05/etc/environment 

If I understand the Docker documentation correctly. The creation of volumes for individual files is supported. Therefore, I do not understand why I am getting this error.

Is there anyone who can explain this? I am running Docker 1.9.1 on Ubuntu 14.04.

+7
docker ubuntu
source share
4 answers

You are using

 -v /etc/environment:/etc/environment 

instead

 -v /etc/environment 

The former displays the container volume on the host volume. The latter tries to create a new volume in / etc / environment and fails because this directory already exists

+3
source share

I think because you are not mounting the file, but declare mount instead. Instead, do the following: -v <full path to a file you want to overwrite the target with>:/etc/environment

0
source share

As docker 1.9 you can create a separate volume container

 docker volume create --name mydatavol01 

Now you can run the container, which is mounted above the volume container

 docker run -ti --rm -v mydatavol01:/local_name_vol01 ubuntu 

most of this new functionality in Docker was available in Kubernetes, so concepts and use cases can be shared ... see a good tutorial at https://www.digitalocean.com/community/tutorials/how-to-share-data-between -docker-containers

Many permutations are available, such as data volumes, which are preserved after the containers are deleted, data containers created from an existing directory, or the ability to share data volumes between multiple containers.

0
source share

Suppose you are on Linux, run the following code

 docker run -it --rm -v /local_dir:/image_root_dir/mount_dir image_name 

Here are a few details:

 -it: interactive terminal --rm: remove container after exit the container -v: volume or say mount your local directory to a volume 

Since the mount function will be the "cover" of the directory on your image, you should always create a new directory under the root directory of the images.

Check out the official documentation. Use binding bindings for more information.

0
source share

All Articles