Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mounting a container volume into another container on a different path

Is it possible to mount a volume from a container into another container on a different path? E.g.

  • contA exposes a volumen /source
  • mounting it in another container docker run --volumes-from contA -v /source/somedir:/etc/otherdir

I'm trying to use this with docker-compose and jwilder/nginx-proxy:

docker-compose.yml

myapp:
  build: .
  command: ./run.sh
  volumes:
    - /source

nginx:
  image: jwilder/nginx-proxy
  volumes_from:
    - myapp
  volumes:
    - /source/vhost.d:/etc/nginx/vhost.d:ro
    - /var/run/docker.sock:/tmp/docker.sock
  links:
    - myapp:myapp

If I'm trying so, I can't see my files at /etc/nginx/vhost.d:

$ docker-compose run nginx bash                                  
root@f200c1c476c7:/app# ls -l
total 32
-rw-r--r-- 1 root root 1076 Apr  9 22:10 Dockerfile
-rw-r--r-- 1 root root 1079 Apr  9 22:10 LICENSE
-rw-r--r-- 1 root root  129 Apr  9 22:10 Procfile
-rw-r--r-- 1 root root 8385 Apr  9 22:10 README.md
-rw-r--r-- 1 root root 5493 Apr  9 22:10 nginx.tmpl
root@f200c1c476c7:/app# ls -l /etc/nginx/vhost.d
total 0
root@f200c1c476c7:/app# ls -l /source/nginx/
total 8
-rw-r--r-- 1 1000 staff 957 Apr 24 07:17 dockerhost.me
like image 692
sspross Avatar asked Apr 24 '15 09:04

sspross


People also ask

Can I mount a volume to multiple containers?

Yes you can add same location as a volume to many docker containers. Additionally you can use --volumes-from to mount your log directory in one container not actually running any application and then use the volumes from this container in your other containers without having to repeat the paths everywhere.

Can two Docker containers mount same volume?

For some development applications, the container needs to write into the bind mount so that changes are propagated back to the Docker host. At other times, the container only needs read access to the data. Multiple containers can mount the same volume.

How do I transfer data from one container to another container?

You can use the docker cp command to copy the file. The first path (Source) is the path in the Docker Container and the second one is the path inside your Local System (Destination).


1 Answers

It doesn't seem possible, considering the syntax - v /host/path:/container/path is reserved for mounting a path from host (and not from another container)

That leaves you with the option of adding to your second container a symbolic link from /etc/otherdir to /source/somedir (which will exist because of the --volumes-from contA directive)

like image 77
VonC Avatar answered Oct 25 '22 16:10

VonC