docker 卷 ls
描述 | 列出卷 |
---|---|
用法 | docker volume ls [OPTIONS] |
别名 | docker volume list |
描述
列出 Docker 已知的所有卷。您可以使用-f
或
--filter
标志进行过滤。有关可用过滤器选项的更多信息,请参阅
过滤部分。
选项
选项 | 默认 | 描述 |
---|---|---|
--cluster | API 1.42+
Swarm
仅显示集群卷,并使用集群卷列表格式 | |
-f, --filter | 提供过滤器值(例如dangling=true ) | |
--format | 使用自定义模板设置输出格式: 'table':以带有列标题的表格格式打印输出(默认) 'table TEMPLATE':使用给定的 Go 模板以表格格式打印输出 'json':以 JSON 格式打印 'TEMPLATE':打印使用给定的 Go 模板输出。有关使用模板格式化输出的更多信息, 请参阅 https://docker.github.net.cn/go/formatting/ | |
-q, --quiet | 仅显示卷名 |
例子
创建卷
$ docker volume create rosemary
rosemary
$ docker volume create tyler
tyler
$ docker volume ls
DRIVER VOLUME NAME
local rosemary
local tyler
过滤(--filter)
过滤标志(-f
或--filter
)格式为“key=value”。如果有多个过滤器,则传递多个标志(例如,--filter "foo=bar" --filter "bif=baz"
)
目前支持的过滤器有:
- 悬空(布尔值 - true 或 false,0 或 1)
- driver(卷驱动程序的名称)
- 标签 (
label=<key>
或label=<key>=<value>
) - 名称(卷的名称)
悬空
过滤器dangling
匹配任何容器未引用的所有卷
$ docker run -d -v tyler:/tmpwork busybox
f86a7dd02898067079c99ceacd810149060a70528eff3754d0b0f1a93bd0af18
$ docker volume ls -f dangling=true
DRIVER VOLUME NAME
local rosemary
司机
过滤driver
器根据驱动程序匹配卷。
以下示例与使用local
驱动程序创建的卷匹配:
$ docker volume ls -f driver=local
DRIVER VOLUME NAME
local rosemary
local tyler
标签
过滤器根据单独的 a 或 a和 a 值label
的存在来匹配体积。label
label
首先,创建一些卷来说明这一点;
$ docker volume create the-doctor --label is-timelord=yes
the-doctor
$ docker volume create daleks --label is-timelord=no
daleks
以下示例过滤器将卷与is-timelord
标签匹配,无论其值如何。
$ docker volume ls --filter label=is-timelord
DRIVER VOLUME NAME
local daleks
local the-doctor
如上面的示例所示,返回带有is-timelord=yes
、 和
的两个卷。is-timelord=no
对标签的key
和 进行过滤,会产生预期的结果:value
$ docker volume ls --filter label=is-timelord=yes
DRIVER VOLUME NAME
local the-doctor
指定多个标签过滤器会产生“与”搜索;应满足所有条件;
$ docker volume ls --filter label=is-timelord=yes --filter label=is-timelord=no
DRIVER VOLUME NAME
姓名
过滤器name
匹配卷名称的全部或部分。
以下过滤器匹配名称包含该rose
字符串的所有卷。
$ docker volume ls -f name=rose
DRIVER VOLUME NAME
local rosemary
格式化输出(--format)
格式化选项 ( --format
) 使用 Go 模板漂亮地打印卷输出。
下面列出了 Go 模板的有效占位符:
占位符 | 描述 |
---|---|
.Name | 卷名 |
.Driver | 音量驱动程序 |
.Scope | 卷范围(本地、全局) |
.Mountpoint | 主机上卷的挂载点 |
.Labels | 分配给该卷的所有标签 |
.Label | 该卷的特定标签的值。例如{{.Label "project.version"}} |
使用该--format
选项时,该volume ls
命令将完全按照模板声明的方式输出数据,或者在使用指令时还
table
包括列标题。
以下示例使用不带标题的模板,并
为所有卷输出由冒号 ( ) 分隔的Name
和条目:Driver
:
$ docker volume ls --format "{{.Name}}: {{.Driver}}"
vol1: local
vol2: local
vol3: local
要以 JSON 格式列出所有卷,请使用以下json
指令:
$ docker volume ls --format json
{"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"}