The -v or --volume command line option or the volume option in a Docker Compose file (e.g. docker-compose.yml) is used to mount a file or directory on your Docker system to a file or directory in the container. For example, let's say you have created a PHP container on Docker. You could mount the /usr/local/docker/images directory on the Docker system to /var/www/images as a volume in the PHP container.
As an example, let's say you have a container named foo, and you want to store the data in the /usr/local/docker/foo/logs on your Docker server in the /var/log directory in the foo container. Let's break down this command.
docker run --volume /usr/local/docker/foo:/var/log foo:latest
Or, a file on the Docker system can be mounted to a file in the container.
docker run --volume /usr/local/docker/foo.txt:/tmp/foo.txt foo:latest
Or, the name of a Docker volume can be used.
docker run --volume volume001:/var/log foo:latest
Three colon separated values are used with the -v or --volume command line option.
Here is an example of how you would mount as volume as ro (read only). The following mount options can be used.
docker run --volume /usr/local/docker/foo:/var/log:ro foo:latest