Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

docker - multiple volumes to single target directory?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...