以下簡單介紹一些清理Docker空間的方法。
步驟一:檢查Docker使用空間, docker system df
如下使用docker system df來查看使用的空間,看看空間是被甚麼東西給吃掉
# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 22 6 3.691GB 2.072GB (56%) Containers 7 4 1.057GB 52.97MB (5%) Local Volumes 22 1 1.143GB 1.143GB (100%) Build Cache 0 0 0B 0B
步驟二:檢查停止docker container, docker ps -a
使用docker ps -a來檢查停止的容器,如下如果是UP以外的的狀態就是有問題的容器,這時可以考慮刪除
# docker ps -a ░▒▓ ✔ │ root@ezdarwin01 15:31:10 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb0ac1193c51 seti/librenms "/sbin/my_init" 4 months ago Up 4 weeks 0.0.0.0:80->80/tcp, :::80->80/tcp, 11211/tcp, 0.0.0.0:514->514/tcp, :::514->514/tcp, 0.0.0.0:514->514/udp, :::514->514/udp, 42217/tcp librenms 9f6d716cda42 mariadb "docker-entrypoint.s…" 4 months ago Up 4 weeks 3306/tcp librenms-db 6bb094cc2776 quay.io/gravitational/teleport:7.3.2 "/usr/bin/dumb-init …" 7 months ago Exited (0) 6 months ago teleport 89f0d8c9c496 grafana/grafana:latest "/run.sh" 7 months ago Exited (255) 4 months ago 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana 4a1d93cd2434 fauria/vsftpd "/usr/sbin/run-vsftp…" 8 months ago Up 4 weeks 0.0.0.0:20-21->20-21/tcp, :::20-21->20-21/tcp vsftpd01
步驟三:刪除停止的容器, docker rm
步驟二發現teloport是沒有啟用狀態,使用docker rm "name or container id"就可以刪除停止的容器。 就
#docker rm teleport ░▒▓ 1 ✘ root@ezdarwin01 15:47:34
teleport
步驟四:刪除image
如果在步驟一發現image佔很多空間,就可以使用下面指令列出image與刪除image
docker rmi "name or image id"可以刪除image,如果沒有顯示名字,可以直接輸入image id刪除
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
aler9/rtsp-simple-server latest 296e01d7b6ca 4 months ago 19.1MB
cloudsploit 0.0.1 0ce16a332d5f 7 months ago 506MB
<none> <none> 9597a1f38622 7 months ago 262MB
<none> <none> 420706c6c269 7 months ago 262MB
<none> <none> 52a0ec36f914 7 months ago 262MB
<none> <none> 86164bdd5a97 7 months ago 262MB
<none> <none> e335e91c9809 7 months ago 262MB
quay.io/gravitational/teleport 7 084d3b08439a 7 months ago 274MB
node lts-alpine3.12 7ae9aa692723 7 months ago 110MB
ccypen/easydarwin p4.1 7353a346f165 7 months ago 384MB
ccypen/easydarwin p0.6 715d049f5763 7 months ago 380MB
grafana/grafana latest ddfae340d068 7 months ago 253MB
mariadb latest e2278f24ac88 8 months ago 410MB
ccypen/easydarwin p0.1 66795daf5d05 8 months ago 380MB
quay.io/gravitational/teleport 7.3.2 e8911f49d4e1 8 months ago 274MB
seti/librenms latest aab2fb26161e 18 months ago 577MB
fauria/vsftpd latest 007276d7208b 21 months ago 255MB
# docker rmi 9597a1f38622
Deleted: sha256:7448a165960e8988bec1a82df9ef10b84e9d0bd3c6da14430b61ca895c5ede73
Deleted: sha256:083093d90e6773dfd3a60c3914c36026c27a8cd434dc78c33232077da325b872
Deleted: sha256:0fe19888e1f25a250b1a6070b875ca8d52cfd23e56696bd03ab9c7bfc1de9b9a
Deleted: sha256:6e3ecca560abdf8e71ee6a6ad9878a6fe4073a624af3818dc9e1579327713d69
Deleted: sha256:e2e3f6af94c6e857dbbefde8674417cbaa54be3f236cf27b6a481f3ccc4992e2
Deleted: sha256:a30bec389764599dc9ba72d675a6b6341c8e963614953cd168495988078599dd
Deleted: sha256:49dd85e74f0099aed9f182c3a2bab043b8e42dccc093d89ce6e64b534d2eda42
Deleted: sha256:ef4473c7218459fd6c9710ef18908af392a231b8bc26c13cbed76f8c50b57929
Deleted: sha256:d6a65307ef5d2b3523dd7bee7f76732e6f0a8c4e04120befe00188af67b3bbcc
Deleted: sha256:d3657e68b9a3e14bb25a92bf68496a8a64b9b2ba816789a283217172e4ee4e8b
步驟四:刪除log
Docker跑久了會產生log,尤其沒有做限制的話,log會無止盡的變大,這時可以用下面指令找出log路徑後,看要直接刪除, 備分還是有其他規畫都可以。
# docker inspect vsftpd01 | grep -G '"LogPath": "*"' | sed -e 's/.*"LogPath": "//g' | sed -e 's/",//g' #vsftpd01也可以改成container id
/var/lib/docker/containers/4a1d93cd2434ee1c6ef03adfa7ca33cb2d56fd7745f7fe10dd7571804a4e0388/4a1d93cd2434ee1c6ef03adfa7ca33cb2d56fd7745f7fe10dd7571804a4e0388-json.log #vsftpd01的log路徑
步驟五:docker prune強制刪除沒有在使用的docker image與container
使用docker system prune -a用不到的docker資料,如下
# docker system prune -a ok 6s root@teleport01 16:23:58
WARNING! This will remove:
- all stopped containers
- all networks 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:
85f8fe36b0c115922317e872fb76311f4448fe91e520ea6165e963cb07b94d23
3ab6577bfef6e4ddf6b9cb04f67df2ce33fcee91ff2be3062a0f71febec935bc
11ebfc97e5930ae6eff5b179a5ba4bd1497a956517fce2f34f9d8486ca8323d2
fef8f6674531f413b70e4d06e55153d91c4e1a361cbdcff6c3b1d52a18011ae9
Deleted Networks:
teleport_teleport
Deleted Images:
untagged: quay.io/gravitational/teleport-lab:8
untagged: quay.io/gravitational/teleport-lab@sha256:08680d1a1a88d8c2cafc650e7969e0d8de54e26f87d4005bdc3b0de3b4bd031c
deleted: sha256:253359b69e5aee9311882c9dd6febf95d887c588b3c96608f197608972a76928
deleted: sha256:c30bea18c0f373a351cc9a13235e311b6013bd7f292c230a8cb404e4dd471cef
deleted: sha256:5c5ab85eda9ea81d82411cd71a4662caf1b3bb648ea810bde6fee68a4b1cb76a
deleted: sha256:985d43fff4fefbbfacf09cf713a4f2191c35d83a532a59ca3fe2efa30fec7d06
deleted: sha256:2d36e458fc5c8ca46b94a32690187e9d6e27abc24a38caca52d1d1e917455d03
deleted: sha256:d675411f0151b12fe172cc160faa96523f152a229e96c297fe3480e3a5b22ec0
deleted: sha256:665a4189e963d2d7cd262dec14378c91a97ad1bc2c48a8404deabc0b95206b83
deleted: sha256:fa29b1fe8b98d7fefd495e2117832002d7f90d57c2fed885be5aa5961fee393f
deleted: sha256:fc5803a835b1700374ea77460f772b8507b089ca9ca3222699b99b8d5772ce09
deleted: sha256:6d09cf752db46167dfa543ee321c4b0fe1e31b7fcd6f5ab89721b376123a0aad
deleted: sha256:779ade05223ce420f5ffec38131b0d53627ff6606baa84a32794e12ac0d25d59
deleted: sha256:ec079b3599973681543c9989d6959a9051145e1a74b205147b12dfc5abbc5cb6
deleted: sha256:0a7e239b963b8b4627071bfcb55490ef23b80732b7340ecf643bb2543aca52e9
deleted: sha256:b280bf55d6497946146cee899a47487add01cd3354a8cff8b322577edc18d11e
deleted: sha256:36ffdceb4c77bf34325fb695e64ea447f688797f2f1e3af224c29593310578d2
Total reclaimed space: 600.8MB
步驟六:其他也可以用的刪除命令
以下命令可以先用ls列出來相關資源再決定要不要刪除,如docker volume ls。
docker container prune # Remove all stopped containers
docker volume prune # Remove all unused volumes
docker image prune # Remove unused images
docker network prune # Remove unused networkemove unused imagesemove unused
沒有留言:
張貼留言