docker network prune
說明 | 移除所有未使用的網路 |
---|---|
用法 | docker network prune [選項] |
說明
移除所有未使用的網路。未使用的網路是指沒有任何容器參考的網路。
選項
選項 | 預設值 | 說明 |
---|---|---|
--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
) 的格式為「鍵=值」。如果有多個篩選條件,請傳遞多個旗標(例如,--filter "foo=bar" --filter "bif=baz"
)
目前支援的篩選器如下:
- until (
<timestamp>
) - 僅移除在指定時間戳記之前建立的網路 - label (
label=<key>
、label=<key>=<value>
、label!=<key>
或label!=<key>=<value>
) - 僅移除具有(或不具有,如果使用label!=...
)指定標籤的網路。
until
篩選器可以是 Unix 時間戳記、日期格式的時間戳記,或是相對於守護行程機器時間計算的 Go 持續時間字串(例如 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 時間戳記時,請輸入秒數[.奈秒],其中秒數是指自 1970 年 1 月 1 日(UTC/GMT 午夜)以來經過的秒數,不計算閏秒(也就是 Unix 紀元或 Unix 時間),而可選的 .nanoseconds 欄位是小於或等於九位數的秒數分數。
label
篩選器接受兩種格式。一種是 label=...
(label=<鍵>
或 label=<鍵>=<值>
),它會移除具有指定標籤的網路。另一種格式是 label!=...
(label!=<鍵>
或 label!=<鍵>=<值>
),它會移除沒有指定標籤的網路。
以下指令會移除建立超過 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