Install multiple volumes on a docker container?

I know that I can mount the directory on my host in the container using something like

docker run -t -i -v '/on/my/host:/on/the/container' ubuntu /bin/bash 

Is there a way to create multiple container-container pairs? for example, a comma separated list, or pass to an array?

+116
docker
Sep 18 '13 at 0:04 on
source share
5 answers

Pass a few -v arguments.

For example:

 docker -v /on/my/host/1:/on/the/container/1 \ -v /on/my/host/2:/on/the/container/2 \ ... 
+217
Sep 18 '13 at 0:11
source share

You can use -v several times in the docker run -v docker run to mount multiple directories in the container:

 docker run -t -i \ -v '/on/my/host/test1:/on/the/container/test1' \ -v '/on/my/host/test2:/on/the/container/test2' \ ubuntu /bin/bash 
+4
Jan 18 '19 at 9:08
source share

You can only read or read and write only on the volume

 docker -v /on/my/host/1:/on/the/container/1:ro \ docker -v /on/my/host/2:/on/the/container/2:rw \ 
+2
May 08 '18 at 18:13
source share

Docker now recommends switching to using --mount.

Mounting a volume multiple times is also explained in detail in the current Docker documentation.

From: https://docs.docker.com/storage/bind-mounts/

 $ docker run -d \ -it \ --name devtest \ --mount type=bind,source="$(pwd)"/target,target=/app \ --mount type=bind,source="$(pwd)"/target,target=/app2,readonly,bind-propagation=rslave \ nginx:latest 

The original old answer should still work; just trying to save the answer according to the current best known method.

0
Jul 19 '19 at 16:26
source share

Or you can do

 docker run -v /var/volume1 -v /var/volume2 DATA busybox true 
-7
Mar 26 '14 at 22:08
source share



All Articles