bind mount is type of mount. It's one of the three way on how you can persist data from a container. See Docker - Data Persistence
The file or directory is referenced by its full or relative path on the host machine. The file or directory does not need to exist on the Docker host already.
docker run -d \
-it \
--name devtest \
--mount type=bind,source="$(pwd)"/target,target=/app \
nginx:latest
The -v or --volume options when mounting a bind mount, consists of three fields, separated by colon characters :
Example:
docker run -it --rm -v /c/tmp:/pathInContainer/ ubuntu bash
docker run ^
--name containerName ^
-v %cd%:/var/www/html/ ^
imageName
docker inspect containerName
"Mounts": [
{
"Type": "bind",
"Source": "/host_mnt/c/code/bdm",
"Destination": "/ansible/playbooks",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
This shows that:
I got this error using MGINX. Below is a workaround
SOURCE_MOUNT_POINT=$(cygpath -u $(readlink -f ../myRelativePath))
# then mount
docker run \
--mount type=bind,source=/$SOURCE_MOUNT_POINT,target=/var/www/html \
repo/image:tag
Error response from daemon: error while creating mount source path '/host_mnt/d/dokuwiki': mkdir /host_mnt/d: file exists
Just restart docker
On Windows 10
docker: Error response from daemon: Mount denied:
The source path "D:/tmp"
doesn't exist and is not known to Docker.
See 'docker run --help'.
Solution: The credentials for the mount have expired, reset them