Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - cannot mount volume over existing file, file exists

I'm trying to build 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. Creating volumes for single files is supported. So I don't understand why I get this error.

Is there somebody who can explain this to me? I'm running Docker 1.9.1 on Ubuntu 14.04.

like image 473
Sven van de Scheur Avatar asked Nov 24 '15 20:11

Sven van de Scheur


2 Answers

You should use:

-v /etc/environment:/etc/environment

instead of:

-v /etc/environment

The former maps container volume to the host volume. The latter tries to create a new volume at /etc/environment and fails since this directory already exists.

like image 120
dr.scre Avatar answered Sep 24 '22 00:09

dr.scre


Suppose you are under Linux, run the following code

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

Here is some detail:

-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 'cover' the directory in your image, your should always make a new directory under your images root directory.

Visit official documentation Use bind mounts to get more information.

like image 1
Fuevo Avatar answered Sep 23 '22 00:09

Fuevo