diff --git a/content/get-started/docker-concepts/running-containers/sharing-local-files.md b/content/get-started/docker-concepts/running-containers/sharing-local-files.md index bf324ff296a1..6f55002951b5 100644 --- a/content/get-started/docker-concepts/running-containers/sharing-local-files.md +++ b/content/get-started/docker-concepts/running-containers/sharing-local-files.md @@ -38,7 +38,7 @@ Here's a way to use `docker run` to start a container using a bind mount and map $ docker run -v /HOST/PATH:/CONTAINER/PATH -it nginx ``` -The `--mount` flag offers more advanced features and granular control, making it suitable for complex mount scenarios or production deployments. If you use `--mount` to bind-mount a file or directory that doesn't yet exist on the Docker host, the `docker run` command doesn't automatically create it for you but generates an error. +The `--mount` flag offers more advanced features and granular control, making it suitable for complex mount scenarios or production deployments. By default, if you use `--mount` to bind-mount a file or directory that doesn't yet exist on the Docker host, the `docker run` command doesn't automatically create it for you but generates an error. ```console $ docker run --mount type=bind,source=/HOST/PATH,target=/CONTAINER/PATH,readonly nginx diff --git a/content/manuals/engine/storage/bind-mounts.md b/content/manuals/engine/storage/bind-mounts.md index 3badc3c612b5..23e480faefc3 100644 --- a/content/manuals/engine/storage/bind-mounts.md +++ b/content/manuals/engine/storage/bind-mounts.md @@ -87,7 +87,7 @@ If you use `--volume` to bind-mount a file or directory that does not yet exist on the Docker host, Docker automatically creates the directory on the host for you. It's always created as a directory. -`--mount` does not automatically create a directory if the specified mount +By default, `--mount` does not automatically create a directory if the specified mount path does not exist on the host. Instead, it produces an error: ```console @@ -95,6 +95,13 @@ $ docker run --mount type=bind,src=/dev/noexist,dst=/mnt/foo alpine docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/noexist. ``` +You can use the `bind-create-src` option to automatically create the source directory +on the host if it doesn't exist: + +```console +$ docker run --mount type=bind,src=/dev/mydir,dst=/mnt/foo,bind-create-src alpine +``` + ### Options for --mount The `--mount` flag consists of multiple key-value pairs, separated by commas @@ -107,12 +114,13 @@ $ docker run --mount type=bind,src=,dst=[,=