Skip to content

Commit 489c731

Browse files
committed
engine: add bind-create-src mount option
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 7c2d7ac commit 489c731

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

content/get-started/docker-concepts/running-containers/sharing-local-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Here's a way to use `docker run` to start a container using a bind mount and map
3838
$ docker run -v /HOST/PATH:/CONTAINER/PATH -it nginx
3939
```
4040

41-
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.
41+
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.
4242

4343
```console
4444
$ docker run --mount type=bind,source=/HOST/PATH,target=/CONTAINER/PATH,readonly nginx

content/manuals/engine/storage/bind-mounts.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,21 @@ If you use `--volume` to bind-mount a file or directory that does not yet
8787
exist on the Docker host, Docker automatically creates the directory on the
8888
host for you. It's always created as a directory.
8989

90-
`--mount` does not automatically create a directory if the specified mount
90+
By default, `--mount` does not automatically create a directory if the specified mount
9191
path does not exist on the host. Instead, it produces an error:
9292

9393
```console
9494
$ docker run --mount type=bind,src=/dev/noexist,dst=/mnt/foo alpine
9595
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/noexist.
9696
```
9797

98+
You can use the `bind-create-src` option to automatically create the source directory
99+
on the host if it doesn't exist:
100+
101+
```console
102+
$ docker run --mount type=bind,src=/home/user/mydir,dst=/mnt/foo,bind-create-src alpine
103+
```
104+
98105
### Options for --mount
99106

100107
The `--mount` flag consists of multiple key-value pairs, separated by commas
@@ -107,12 +114,13 @@ $ docker run --mount type=bind,src=<host-path>,dst=<container-path>[,<key>=<valu
107114

108115
Valid options for `--mount type=bind` include:
109116

110-
| Option | Description |
111-
| ------------------------------ | --------------------------------------------------------------------------------------------------------------- |
112-
| `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. |
113-
| `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. |
114-
| `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). |
115-
| `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). |
117+
| Option | Description |
118+
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119+
| `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. |
120+
| `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. |
121+
| `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). |
122+
| `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). |
123+
| `bind-create-src` | Automatically creates the source directory on the host if it doesn't exist. By default, `--mount` produces an error if the source path doesn't exist on the daemon. |
116124

117125
```console {title="Example"}
118126
$ docker run --mount type=bind,src=.,dst=/project,ro,bind-propagation=rshared

0 commit comments

Comments
 (0)