Skip to content

Commit 32aa575

Browse files
ndeloofvvoland
authored andcommitted
docs/service: Document bind-create-src
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent c747cff commit 32aa575

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

docs/reference/commandline/service_create.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,22 @@ The following options can only be used for bind mounts (`type=bind`):
457457
When the option is not specified, the default behavior corresponds to setting <tt>enabled</tt>.
458458
</td>
459459
</tr>
460+
<tr>
461+
<td><b>bind-create-src</b></td>
462+
<td>
463+
By default, bind mounts require the source path to exist on the daemon host. This is a significant difference
464+
from the <tt>-v</tt> flag, which creates the source path if it doesn't exist.<br />
465+
<br />
466+
Set <tt>bind-create-src</tt> to create the source path on the daemon host if it doesn't exist.<br />
467+
<br />
468+
A value is optional:<br />
469+
<br />
470+
<ul>
471+
<li><tt>true</tt> or <tt>1</tt>: Create path on the daemon host if it doesn't exist.</li>
472+
<li><tt>false</tt> or <tt>0</tt>: Default behavior. Produces an error if the source path doesn't exist on the daemon host.</li>
473+
</ul>
474+
</td>
475+
</tr>
460476
</table>
461477

462478
##### Bind propagation
@@ -591,7 +607,8 @@ or `--volume` flag for `docker run`, with some important exceptions:
591607

592608
- When you use `--mount` with `type=bind`, the host-path must refer to an *existing*
593609
path on the host. The path will not be created for you and the service will fail
594-
with an error if the path does not exist.
610+
with an error if the path does not exist. You can use `bind-create-src` to
611+
create the host path if it doesn't exist.
595612

596613
- The `--mount` flag does not allow you to relabel a volume with `Z` or `z` flags,
597614
which are used for `selinux` labeling.

docs/reference/run.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ two paths. The `source` path is the location on the host that you want to
252252
bind mount into the container. The `target` path is the mount destination
253253
inside the container.
254254

255+
By default, bind mounts require the source path to exist on the daemon host. If the
256+
source path doesn't exist, an error is returned. To create the source path on
257+
the daemon host if it doesn't exist, use the `bind-create-src` option:
258+
259+
```console
260+
$ docker run -it --mount type=bind,source=[PATH],target=[PATH],bind-create-src busybox
261+
```
262+
255263
Bind mounts are read-write by default, meaning that you can both read and write
256264
files to and from the mounted location from the container. Changes that you
257265
make, such as adding or editing files, are reflected on the host filesystem:

0 commit comments

Comments
 (0)