Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple volumes to single target directory?

Tags:

docker

unionfs

Is there a way to mount multiple volumes from a host to form a single target mount point? A bit like this:

docker run --name ubuntu_bash \
    --rm --interactive --tty \
    --volume=/media/Large/videos:/videos \
    --volume=/media/Small/videos:/videos \
    ubuntu find /videos

I'm guessing the answer is no but with "overlay" having so many meanings in the context of Docker it's a bit difficult to search for this on the web.

If not, is there a Docker Store image that might help? Unfortunately a lot of Docker images don't give sufficient instructions on how to use them.

like image 950
Sridhar Sarnobat Avatar asked Aug 28 '17 23:08

Sridhar Sarnobat


People also ask

Can a container have multiple volumes?

You can manage volumes using Docker CLI commands or the Docker API. Volumes work on both Linux and Windows containers. Volumes can be more safely shared among multiple containers. Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.

Is it possible to can use multiple volumes from flags in one Docker Run command?

Using Multiple Volumes. Suppose we want to mount two different volumes for our web application, but one of those paths must be read-only. We can also use anonymous volumes, for example, by including -v container-path. Docker will create it for us, but it gets removed once we delete the container.

Why would you choose data volume containers over data volumes?

In addition, volumes are often a better choice than persisting data in a container's writable layer, because a volume does not increase the size of the containers using it, and the volume's contents exist outside the lifecycle of a given container.

What is $PWD in Docker?

PWD is a Docker playground which allows users to run Docker commands in a matter of seconds. It gives the experience of having a free Alpine Linux Virtual Machine in browser, where you can build and run Docker containers and even create clusters in Docker Swarm Mode.


1 Answers

There's no built in docker method to do this for volumes, they are typically a bind mount for local volumes. The unionfs mounts are for the image layers used to create your container, but volumes act completely outside of this and mount on top of the unionfs intercepting all filesystem requests to that directory.

If you create a solution to do this with a linux mount, you can define a volume mount in docker with the same linux mount options. For example, the method to do an NFS mount in docker is the following:

# For a reusable volume
$ docker volume create --driver local \
    --opt type=nfs \
    --opt o=addr=192.168.1.1,rw \
    --opt device=:/path/to/dir \
    foo

# For a local container with docker run
$ docker run -it --rm \
  --mount type=volume,dst=/container/path,volume-driver=local,volume-opt=type=nfs,volume-opt=o=addr=192.168.1.1,volume-opt=device=:/host/path \
  foo

# For a swarm mode service
$ docker service create \
  --mount type=volume,dst=/container/path,volume-driver=local,volume-opt=type=nfs,volume-opt=o=addr=192.168.1.1,volume-opt=device=:/host/path \
  foo

Note in all of these examples the volume-driver is local, and volume-opt is used to pass all of the mount options like you would on a mount command.

like image 55
BMitch Avatar answered Oct 29 '22 09:10

BMitch