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

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 "https://stackoverflow.com/"(.*)"/ { gsub(/"/,"",$2); print $2 }')
SRV2=$(docker inspect DATA2 | grep "vfs/dir" | awk "https://stackoverflow.com/"(.*)"/ { 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.

Leave a Comment