Sharing host data
Earlier, we described the steps to create a data volume in a Docker image using the VOLUME
instruction in the Dockerfile
. However, Docker does not provide any mechanism to mount the host directory or file during the build time in order to ensure the Docker images to be portable. The only provision Docker provides is to mount the host directory or file to a container's data volume during the container's launch. Docker exposes the host directory or file mounting facility through the -v
option of the docker run
subcommand. The -v
option has five different formats, enumerated as follows:
-v <container mount path>
-v <host path>:<container mount path>
-v <host path>:<container mount path>:<read write mode>
-v <volume name>:<container mount path>
-v <volume name>:<container mount path>:<read write mode>
The <host path>
format is an absolute path in the Docker host, <container mount path>
is an absolute path...