It is possible to mount a host directory to a specific path in your container using the -v
or --volume
command line option. The following example will mount /etc
on the host to /mnt/etc
in the container:
(on linux) docker run -v "/etc:/mnt/etc" alpine cat /mnt/etc/passwd
(on windows) docker run -v "/c/etc:/mnt/etc" alpine cat /mnt/etc/passwd
The default access to the volume inside the container is read-write. To mount a volume read-only inside of a container, use the suffix :ro
:
docker run -v "/etc:/mnt/etc:ro" alpine touch /mnt/etc/passwd