...

Text file src/github.com/docker/cli/docs/reference/commandline/volume_ls.md

Documentation: github.com/docker/cli/docs/reference/commandline

     1# volume ls
     2
     3<!---MARKER_GEN_START-->
     4List volumes
     5
     6### Aliases
     7
     8`docker volume ls`, `docker volume list`
     9
    10### Options
    11
    12| Name                                   | Type     | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                          |
    13|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
    14| `--cluster`                            |          |         | Display only cluster volumes, and use cluster volume list formatting                                                                                                                                                                                                                                                                                                                                                                 |
    15| [`-f`](#filter), [`--filter`](#filter) | `filter` |         | Provide filter values (e.g. `dangling=true`)                                                                                                                                                                                                                                                                                                                                                                                         |
    16| [`--format`](#format)                  | `string` |         | Format output using a custom template:<br>'table':            Print output in table format with column headers (default)<br>'table TEMPLATE':   Print output in table format using the given Go template<br>'json':             Print in JSON format<br>'TEMPLATE':         Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
    17| `-q`, `--quiet`                        |          |         | Only display volume names                                                                                                                                                                                                                                                                                                                                                                                                            |
    18
    19
    20<!---MARKER_GEN_END-->
    21
    22## Description
    23
    24List all the volumes known to Docker. You can filter using the `-f` or
    25`--filter` flag. Refer to the [filtering](#filter) section for more
    26information about available filter options.
    27
    28## Examples
    29
    30### Create a volume
    31
    32```console
    33$ docker volume create rosemary
    34
    35rosemary
    36
    37$ docker volume create tyler
    38
    39tyler
    40
    41$ docker volume ls
    42
    43DRIVER              VOLUME NAME
    44local               rosemary
    45local               tyler
    46```
    47
    48### <a name="filter"></a> Filtering (--filter)
    49
    50The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more
    51than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`)
    52
    53The currently supported filters are:
    54
    55- dangling (Boolean - true or false, 0 or 1)
    56- driver (a volume driver's name)
    57- label (`label=<key>` or `label=<key>=<value>`)
    58- name (a volume's name)
    59
    60#### dangling
    61
    62The `dangling` filter matches on all volumes not referenced by any containers
    63
    64```console
    65$ docker run -d  -v tyler:/tmpwork  busybox
    66
    67f86a7dd02898067079c99ceacd810149060a70528eff3754d0b0f1a93bd0af18
    68$ docker volume ls -f dangling=true
    69DRIVER              VOLUME NAME
    70local               rosemary
    71```
    72
    73#### driver
    74
    75The `driver` filter matches volumes based on their driver.
    76
    77The following example matches volumes that are created with the `local` driver:
    78
    79```console
    80$ docker volume ls -f driver=local
    81
    82DRIVER              VOLUME NAME
    83local               rosemary
    84local               tyler
    85```
    86
    87#### label
    88
    89The `label` filter matches volumes based on the presence of a `label` alone or
    90a `label` and a value.
    91
    92First, create some volumes to illustrate this;
    93
    94```console
    95$ docker volume create the-doctor --label is-timelord=yes
    96
    97the-doctor
    98$ docker volume create daleks --label is-timelord=no
    99
   100daleks
   101```
   102
   103The following example filter matches volumes with the `is-timelord` label
   104regardless of its value.
   105
   106```console
   107$ docker volume ls --filter label=is-timelord
   108
   109DRIVER              VOLUME NAME
   110local               daleks
   111local               the-doctor
   112```
   113
   114As the above example demonstrates, both volumes with `is-timelord=yes`, and
   115`is-timelord=no` are returned.
   116
   117Filtering on both `key` *and* `value` of the label, produces the expected result:
   118
   119```console
   120$ docker volume ls --filter label=is-timelord=yes
   121
   122DRIVER              VOLUME NAME
   123local               the-doctor
   124```
   125
   126Specifying multiple label filter produces an "and" search; all conditions
   127should be met;
   128
   129```console
   130$ docker volume ls --filter label=is-timelord=yes --filter label=is-timelord=no
   131
   132DRIVER              VOLUME NAME
   133```
   134
   135#### name
   136
   137The `name` filter matches on all or part of a volume's name.
   138
   139The following filter matches all volumes with a name containing the `rose` string.
   140
   141```console
   142$ docker volume ls -f name=rose
   143
   144DRIVER              VOLUME NAME
   145local               rosemary
   146```
   147
   148### <a name="format"></a> Format the output (--format)
   149
   150The formatting options (`--format`) pretty-prints volumes output
   151using a Go template.
   152
   153Valid placeholders for the Go template are listed below:
   154
   155| Placeholder   | Description                                                                           |
   156|---------------|---------------------------------------------------------------------------------------|
   157| `.Name`       | Volume name                                                                           |
   158| `.Driver`     | Volume driver                                                                         |
   159| `.Scope`      | Volume scope (local, global)                                                          |
   160| `.Mountpoint` | The mount point of the volume on the host                                             |
   161| `.Labels`     | All labels assigned to the volume                                                     |
   162| `.Label`      | Value of a specific label for this volume. For example `{{.Label "project.version"}}` |
   163
   164When using the `--format` option, the `volume ls` command will either
   165output the data exactly as the template declares or, when using the
   166`table` directive, includes column headers as well.
   167
   168The following example uses a template without headers and outputs the
   169`Name` and `Driver` entries separated by a colon (`:`) for all volumes:
   170
   171```console
   172$ docker volume ls --format "{{.Name}}: {{.Driver}}"
   173
   174vol1: local
   175vol2: local
   176vol3: local
   177```
   178
   179To list all volumes in JSON format, use the `json` directive:
   180
   181```console
   182$ docker volume ls --format json
   183{"Driver":"local","Labels":"","Links":"N/A","Mountpoint":"/var/lib/docker/volumes/docker-cli-dev-cache/_data","Name":"docker-cli-dev-cache","Scope":"local","Size":"N/A"}
   184```
   185
   186## Related commands
   187
   188* [volume create](volume_create.md)
   189* [volume inspect](volume_inspect.md)
   190* [volume rm](volume_rm.md)
   191* [volume prune](volume_prune.md)
   192* [Understand Data Volumes](https://docs.docker.com/storage/volumes/)

View as plain text