docker system prune
說明 | 移除未使用的資料 |
---|---|
用法 | docker system prune [選項] |
說明
移除所有未使用的容器、網路、映像檔(包括懸空和未使用的),以及選擇性地移除磁碟區。
選項
選項 | 預設值 | 說明 |
---|---|---|
-a, --all | 移除所有未使用的映像檔,而不僅僅是懸空的映像檔 | |
--filter | API 1.28+ 提供篩選值(例如 label=<key>=<value> ) | |
-f, --force | 不提示確認 | |
--volumes | 修剪匿名磁碟區 |
範例
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- unused build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
f44f9b81948b3919590d5f79a680d8378f1139b41952e219830a33027c80c867
792776e68ac9d75bce4092bc1b5cc17b779bc926ab04f4185aec9bf1c0d4641f
Deleted Networks:
network1
network2
Deleted Images:
untagged: hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a
Total reclaimed space: 1.84kB
預設情況下,不會移除磁碟區,以防止在目前沒有容器使用磁碟區的情況下刪除重要資料。執行命令時使用 --volumes
旗標也可以修剪匿名磁碟區
$ docker system prune -a --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all anonymous volumes not used by at least one container
- all images without at least one container associated to them
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
0998aa37185a1a7036b0e12cf1ac1b6442dcfa30a5c9650a42ed5010046f195b
73958bfb884fa81fa4cc6baf61055667e940ea2357b4036acbbe25a60f442a4d
Deleted Networks:
my-network-a
my-network-b
Deleted Volumes:
named-vol
Deleted Images:
untagged: my-curl:latest
deleted: sha256:7d88582121f2a29031d92017754d62a0d1a215c97e8f0106c586546e7404447d
deleted: sha256:dd14a93d83593d4024152f85d7c63f76aaa4e73e228377ba1d130ef5149f4d8b
untagged: alpine:3.3
deleted: sha256:695f3d04125db3266d4ab7bbb3c6b23aa4293923e762aa2562c54f49a28f009f
untagged: alpine:latest
deleted: sha256:ee4603260daafe1a8c2f3b78fd760922918ab2441cbb2853ed5c439e59c52f96
deleted: sha256:9007f5987db353ec398a223bc5a135c5a9601798ba20a1abba537ea2f8ac765f
deleted: sha256:71fa90c8f04769c9721459d5aa0936db640b92c8c91c9b589b54abd412d120ab
deleted: sha256:bb1c3357b3c30ece26e6604aea7d2ec0ace4166ff34c3616701279c22444c0f3
untagged: my-jq:latest
deleted: sha256:6e66d724542af9bc4c4abf4a909791d7260b6d0110d8e220708b09e4ee1322e1
deleted: sha256:07b3fa89d4b17009eb3988dfc592c7d30ab3ba52d2007832dffcf6d40e3eda7f
deleted: sha256:3a88a5c81eb5c283e72db2dbc6d65cbfd8e80b6c89bb6e714cfaaa0eed99c548
Total reclaimed space: 13.5 MB
篩選 (--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 時間戳記、日期格式的時間戳記或 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=<key>
或 label=<key>=<value>
),它會移除具有指定標籤的容器、映像檔、網路和磁碟區。另一種格式是 label!=...
(label!=<key>
或 label!=<key>=<value>
),它會移除沒有指定標籤的容器、映像檔、網路和磁碟區。