-
Notifications
You must be signed in to change notification settings - Fork 8.2k
engine: add bind-create-src mount option #24140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,14 +87,21 @@ 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 | ||
| $ 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading example using /dev directory The example uses Per STYLE.md code example guidance ("Use realistic text"), this example should use a realistic user directory that users might actually create and bind-mount. Suggestion: Change Note: The |
||
| ``` | ||
|
|
||
| ### 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=<host-path>,dst=<container-path>[,<key>=<valu | |
|
|
||
| Valid options for `--mount type=bind` include: | ||
|
|
||
| | Option | Description | | ||
| | ------------------------------ | --------------------------------------------------------------------------------------------------------------- | | ||
| | `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. | | ||
| | `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. | | ||
| | `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). | | ||
| | `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). | | ||
| | Option | Description | | ||
| | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `source`, `src` | The location of the file or directory on the host. This can be an absolute or relative path. | | ||
| | `destination`, `dst`, `target` | The path where the file or directory is mounted in the container. Must be an absolute path. | | ||
| | `readonly`, `ro` | If present, causes the bind mount to be [mounted into the container as read-only](#use-a-read-only-bind-mount). | | ||
| | `bind-propagation` | If present, changes the [bind propagation](#configure-bind-propagation). | | ||
| | `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. | | ||
|
|
||
| ```console {title="Example"} | ||
| $ docker run --mount type=bind,src=.,dst=/project,ro,bind-propagation=rshared | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terminology inconsistency between "source directory" and "source path"
The text here uses "source directory" but the error message directly above uses "bind source path does not exist" and the table below uses "source path" in "the source path doesn't exist on the daemon".
For terminology consistency per STYLE.md, this should use "source path" to match error messages and table descriptions. This helps users since they'll encounter "source path" in error messages.
Suggestion: Change "automatically create the source directory" to "automatically create the source path"