[docker] Mounting multiple volumes on a docker container?

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

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

Is there a way to create more than one host-container pair? e.g. a comma-separated list, or pass in an array?

This question is related to docker

The answer is


Docker now recommends migrating towards using --mount.

Multiple volume mounts are 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

Original older answer should still work; just trying to keep the answer aligned to current best known method.


You can use -v option multiple times in docker run command to mount multiple directory in 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

On Windows: if you had to mount two directories E:\data\dev & E:\data\dev2

Use:

docker run -v E:\data\dev:c:/downloads -v E:\data\dev2 c:/downloads2 -i --publish 1111:80 -P SomeBuiltContainerName:SomeLabel


Or you can do

docker run -v /var/volume1 -v /var/volume2 DATA busybox true

You can have Read only 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 \

Pass multiple -v arguments.

For instance:

docker -v /on/my/host/1:/on/the/container/1 \
       -v /on/my/host/2:/on/the/container/2 \
       ...