Skip to content

Commit e4b70a5

Browse files
authored
Merge pull request #24140 from dvdksn/bind-create-src
engine: add bind-create-src mount option
2 parents 4700cce + 489c731 commit e4b70a5

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
@@ -88,14 +88,21 @@ If you use `--volume` to bind-mount a file or directory that does not yet
8888
exist on the Docker host, Docker automatically creates the directory on the
8989
host for you. It's always created as a directory.
9090

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

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

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

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

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

111-
| Option | Description |
112-
| ------------------------------ | --------------------------------------------------------------------------------------------------------------- |
113-
| `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. |
114-
| `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. |
115-
| `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). |
116-
| `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). |
118+
| Option | Description |
119+
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120+
| `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. |
121+
| `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. |
122+
| `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). |
123+
| `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). |
124+
| `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. |
117125

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

0 commit comments

Comments
 (0)