How to map volume paths using Docker's --volumes-from?

docker

Solution

It can be done, but it is not supported at this moment in docker commandline interface.

How-to

Find the volumes directories:

docker inspect DATA1 | grep "vfs/dir"
# output something like:
# "/srv": "/var/lib/docker/vfs/dir/<long vol id>"

So, you can automate this, and mount these directories at mount points of your choice:

# load directories in variables:
SRV1=$(docker inspect DATA1 | grep "vfs/dir" | awk '/"(.*)"/ { gsub(/"/,"",$2); print $2 }')
SRV2=$(docker inspect DATA2 | grep "vfs/dir" | awk '/"(.*)"/ { gsub(/"/,"",$2); print $2 }')

now, mount these volumes by real directories instead of the --volumes-from:

docker run -t -i -v $SRV1:/srv1 -v $SRV2:/srv2 ubuntu bash

IMO, the functionality is identical, because this is the same thing that is done when using `--volumes-from`.

Problem

I'm new to Docker and am excited about using the `--volumes-from` feature but there's something I'm not understanding. If I want to use `--volumes-from` with two data-only containers, each of which exports volumes named `/srv`, how to I prevent the volume paths from colliding? I can map volume names when creating a bind mount using `[host-dir]:[container-dir]`; how do I do that with `--volumes-from`? So what I want would look something like this: ``` docker run --name=DATA1 --volume=/srv busybox true docker run --name=DATA2 --volume=/srv busybox true docker run -t -i -rm --volumes-from DATA1:/srv1 --volumes-from DATA2:/srv2 ubuntu bash ```

Original source

Related problems