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