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?
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 \
...
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
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 \