Home Explore Blog CI



docker

3rd chunk of `content/manuals/engine/storage/volumes.md`
87e221b41404539a8c47610d9088b5ba3bd4104fbfb8c33b0000000100000fc8
and each consisting of a `<key>=<value>` tuple. The order of the keys isn't
significant.

```console
$ docker run --mount type=volume[,src=<volume-name>],dst=<mount-path>[,<key>=<value>...]
```

Valid options for `--mount type=volume` include:

| Option                         | Description                                                                                                                                                                                                                     |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `source`, `src`                | The source of the mount. For named volumes, this is the name of the volume. For anonymous volumes, this field is omitted.                                                                                                       |
| `destination`, `dst`, `target` | The path where the file or directory is mounted in the container.                                                                                                                                                               |
| `volume-subpath`               | A path to a subdirectory within the volume to mount into the container. The subdirectory must exist in the volume before the volume is mounted to a container. See [Mount a volume subdirectory](#mount-a-volume-subdirectory). |
| `readonly`, `ro`               | If present, causes the volume to be [mounted into the container as read-only](#use-a-read-only-volume).                                                                                                                         |
| `volume-nocopy`                | If present, data at the destination isn't copied into the volume if the volume is empty. By default, content at the target destination gets copied into a mounted volume if empty.                                              |
| `volume-opt`                   | Can be specified more than once, takes a key-value pair consisting of the option name and its value.                                                                                                                            |

```console {title="Example"}
$ docker run --mount type=volume,src=myvolume,dst=/data,ro,volume-subpath=/foo
```

### Options for --volume

The `--volume` or `-v` flag consists of three fields, separated by colon
characters (`:`). The fields must be in the correct order.

```console
$ docker run -v [<volume-name>:]<mount-path>[:opts]
```

In the case of named volumes, the first field is the name of the volume, and is
unique on a given host machine. For anonymous volumes, the first field is
omitted. The second field is the path where the file or directory is mounted in
the container.

The third field is optional, and is a comma-separated list of options. Valid
options for `--volume` with a data volume include:

| Option           | Description                                                                                                                                                                        |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `readonly`, `ro` | If present, causes the volume to be [mounted into the container as read-only](#use-a-read-only-volume).                                                                            |
| `volume-nocopy`  | If present, data at the destination isn't copied into the volume if the volume is empty. By default, content at the target destination gets copied into a mounted volume if empty. |

```console {title="Example"}
$ docker run -v myvolume:/data:ro
```

## Create and manage volumes

Unlike a bind mount, you can create and manage volumes outside the scope of any

Title: Volume Mounting Options: --mount and --volume Flags
Summary
The `--mount` flag offers various options for volume mounting, including specifying the source, destination, volume subpath, read-only status, disabling data copying on empty volumes, and volume-specific options. The `--volume` flag offers a simpler syntax, primarily for specifying the volume name, mount path, and read-only status or disabling data copying. The `--mount` flag is generally preferred due to its explicitness and expanded functionality.