diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 51572eb92f..878670f939 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1518,6 +1518,7 @@ _docker_container_run_and_create() { --memory-swap --memory-swappiness --memory-reservation + --mount --name --network --network-alias diff --git a/contrib/completion/fish/docker.fish b/contrib/completion/fish/docker.fish index f3dddd9277..38957b8b77 100644 --- a/contrib/completion/fish/docker.fish +++ b/contrib/completion/fish/docker.fish @@ -138,6 +138,7 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l link -d 'Add complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s m -l memory -d 'Memory limit (format: [], where unit = b, k, m or g)' complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l mac-address -d 'Container MAC address (e.g., 92:d0:c6:0a:29:33)' complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l memory-swap -d "Total memory usage (memory + swap), set '-1' to disable swap (format: [], where unit = b, k, m or g)" +complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l mount -d 'Attach a filesystem mount to the container' complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l name -d 'Assign a name to the container' complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l net -d 'Set the Network mode for the container' complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s P -l publish-all -d 'Publish all exposed ports to random ports on the host interfaces' @@ -330,6 +331,7 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l link -d 'Add li complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s m -l memory -d 'Memory limit (format: [], where unit = b, k, m or g)' complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l mac-address -d 'Container MAC address (e.g., 92:d0:c6:0a:29:33)' complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l memory-swap -d "Total memory usage (memory + swap), set '-1' to disable swap (format: [], where unit = b, k, m or g)" +complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l mount -d 'Attach a filesystem mount to the container' complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l name -d 'Assign a name to the container' complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l net -d 'Set the Network mode for the container' complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s P -l publish-all -d 'Publish all exposed ports to random ports on the host interfaces' diff --git a/contrib/completion/zsh/_docker b/contrib/completion/zsh/_docker index 938a1f5af0..a791353a88 100644 --- a/contrib/completion/zsh/_docker +++ b/contrib/completion/zsh/_docker @@ -629,6 +629,7 @@ __docker_container_subcommand() { "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" "($help)--mac-address=[Container MAC address]:MAC address: " + "($help)*--mount=[Attach a filesystem mount to the container]:mount: " "($help)--name=[Container name]:name: " "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " diff --git a/docs/reference/commandline/create.md b/docs/reference/commandline/create.md index 0fbe07fbe2..c2189b5ea8 100644 --- a/docs/reference/commandline/create.md +++ b/docs/reference/commandline/create.md @@ -85,6 +85,7 @@ Options: --memory-reservation string Memory soft limit --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) + --mount value Attach a filesytem mount to the container (default []) --name string Assign a name to the container --network-alias value Add network-scoped alias for the container (default []) --network string Connect a container to a network (default "default") diff --git a/docs/reference/commandline/run.md b/docs/reference/commandline/run.md index 6a9bbd5459..e2e5d0a48c 100644 --- a/docs/reference/commandline/run.md +++ b/docs/reference/commandline/run.md @@ -95,6 +95,7 @@ Options: --memory-reservation string Memory soft limit --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) + --mount value Attach a filesystem mount to the container (default []) --name string Assign a name to the container --network-alias value Add network-scoped alias for the container (default []) --network string Connect a container to a network @@ -316,6 +317,29 @@ docker run -v c:\foo:c:\existing-directory-with-contents ... For in-depth information about volumes, refer to [manage data in containers](https://docs.docker.com/engine/tutorials/dockervolumes/) + +### Add bind-mounts or volumes using the --mount flag + +The `--mount` flag allows you to mount volumes, host-directories and `tmpfs` +mounts in a container. + +The `--mount` flag supports most options that are supported by the `-v` or the +`--volume` flag, but uses a different syntax. For in-depth information on the +`--mount` flag, and a comparison between `--volume` and `--mount`, refer to +the [service create command reference](service_create.md#add-bind-mounts-or-volumes). + +Even though there is no plan to deprecate `--volume`, usage of `--mount` is recommended. + +Examples: + +```bash +$ docker run --read-only --mount type=volume,target=/icanwrite busybox touch /icanwrite/here +``` + +```bash +$ docker run -t -i --mount type=bind,src=/data,dst=/data busybox sh +``` + ### Publish or expose port (-p, --expose) ```bash diff --git a/man/docker-run.1.md b/man/docker-run.1.md index 0ee0a13ee8..257711d196 100644 --- a/man/docker-run.1.md +++ b/man/docker-run.1.md @@ -61,6 +61,7 @@ docker-run - Run a command in a new container [**--memory-reservation**[=*MEMORY-RESERVATION*]] [**--memory-swap**[=*LIMIT*]] [**--memory-swappiness**[=*MEMORY-SWAPPINESS*]] +[**--mount**[=*[MOUNT]*]] [**--name**[=*NAME*]] [**--network-alias**[=*[]*]] [**--network**[=*"bridge"*]] @@ -425,6 +426,42 @@ unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. The IPv6 link-local address will be based on the device's MAC address according to RFC4862. +**--mount**=[*[type=TYPE[,TYPE-SPECIFIC-OPTIONS]]*] + Attach a filesystem mount to the container + + Current supported mount `TYPES` are `bind`, `volume`, and `tmpfs`. + + e.g. + + `type=bind,source=/path/on/host,destination=/path/in/container` + + `type=volume,source=my-volume,destination=/path/in/container,volume-label="color=red",volume-label="shape=round"` + + `type=tmpfs,tmpfs-size=512M,destination=/path/in/container` + + Common Options: + + * `src`, `source`: mount source spec for `bind` and `volume`. Mandatory for `bind`. + * `dst`, `destination`, `target`: mount destination spec. + * `ro`, `read-only`: `true` or `false` (default). + + Options specific to `bind`: + + * `bind-propagation`: `shared`, `slave`, `private`, `rshared`, `rslave`, or `rprivate`(default). See also `mount(2)`. + * `consistency`: `consistent`(default), `cached`, or `delegated`. Currently, only effective for Docker for Mac. + + Options specific to `volume`: + + * `volume-driver`: Name of the volume-driver plugin. + * `volume-label`: Custom metadata. + * `volume-nocopy`: `true`(default) or `false`. If set to `false`, the Engine copies existing files and directories under the mount-path into the volume, allowing the host to access them. + * `volume-opt`: specific to a given volume driver. + + Options specific to `tmpfs`: + + * `tmpfs-size`: Size of the tmpfs mount in bytes. Unlimited by default in Linux. + * `tmpfs-mode`: File mode of the tmpfs in octal. (e.g. `700` or `0700`.) Defaults to `1777` in Linux. + **--name**="" Assign a name to the container @@ -604,6 +641,9 @@ options are the same as the Linux default `mount` flags. If you do not specify any options, the systems uses the following options: `rw,noexec,nosuid,nodev,size=65536k`. + See also `--mount`, which is the successor of `--tmpfs` and `--volume`. + Even though there is no plan to deprecate `--tmpfs`, usage of `--mount` is recommended. + **-u**, **--user**="" Sets the username or UID used and optionally the groupname or GID for the specified command. @@ -704,6 +744,9 @@ change propagation properties of source mount. Say `/` is source mount for To disable automatic copying of data from the container path to the volume, use the `nocopy` flag. The `nocopy` flag can be set on bind mounts and named volumes. +See also `--mount`, which is the successor of `--tmpfs` and `--volume`. +Even though there is no plan to deprecate `--volume`, usage of `--mount` is recommended. + **--volume-driver**="" Container's volume driver. This driver creates volumes specified either from a Dockerfile's `VOLUME` instruction or from the `docker run -v` flag.