docker network prune
| 描述 | 移除所有未使用的网络 |
|---|---|
| 用法 | docker network prune [OPTIONS] |
描述
移除所有未使用的网络。未使用的网络是指没有任何容器引用的网络。
选项
| 选项 | 默认值 | 描述 |
|---|---|---|
--filter | 提供筛选值(例如 until=<timestamp>) | |
-f, --force | 不提示确认 |
示例
$ docker network prune
WARNING! This will remove all custom networks not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Networks:
n1
n2
过滤 (--filter)
筛选标志 (--filter) 的格式为 "key=value"。如果有多个筛选器,则传递多个标志(例如,--filter "foo=bar" --filter "bif=baz")
目前支持的过滤器有:
- until (
<timestamp>) - 仅移除在给定时间戳之前创建的网络 - label (
label=<key>,label=<key>=<value>,label!=<key>, 或label!=<key>=<value>) - 仅移除具有(或不具有,当使用label!=...时)指定标签的网络。
until 过滤器可以是 Unix 时间戳、日期格式的时间戳或 ParseDuration 支持的 Go duration 字符串(例如 10m、1h30m),这些时间戳相对于守护程序机器的时间计算。支持的日期格式时间戳包括 RFC3339Nano、RFC3339、2006-01-02T15:04:05、2006-01-02T15:04:05.999999999、2006-01-02T07:00 和 2006-01-02。如果您未在时间戳末尾提供 Z 或 +-00:00 时区偏移量,将使用守护程序的本地时区。提供 Unix 时间戳时,输入 seconds[.nanoseconds],其中 seconds 是自 1970 年 1 月 1 日(UTC/GMT 午夜)以来经过的秒数(不包括闰秒,又称 Unix 纪元或 Unix 时间),可选的 .nanoseconds 字段是少于九位数字的秒的小数部分。
label 过滤器接受两种格式。一种是 label=... (label=<key> 或 label=<key>=<value>),它会移除带有指定标签的网络。另一种格式是 label!=... (label!=<key> 或 label!=<key>=<value>),它会移除不带指定标签的网络。
以下命令将移除 5 分钟前创建的网络。请注意,诸如 bridge、host 和 none 等系统网络永远不会被清除。
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
7430df902d7a bridge bridge local
ea92373fd499 foo-1-day-ago bridge local
ab53663ed3c7 foo-1-min-ago bridge local
97b91972bc3b host host local
f949d337b1f5 none null local
$ docker network prune --force --filter until=5m
Deleted Networks:
foo-1-day-ago
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
7430df902d7a bridge bridge local
ab53663ed3c7 foo-1-min-ago bridge local
97b91972bc3b host host local
f949d337b1f5 none null local