4

磁盘有限,Docker 垃圾很多怎么办

 1 year ago
source link: https://www.newbe.pro/Others/0x024-What-to-do-with-limited-disks-and-lots-of-Docker-garbage/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

磁盘有限,Docker 垃圾很多怎么办

2023-02-22 5

你的电脑上可能 pull 或者 build 了很多 Docker 镜像,但是你不知道怎么清理,本文将介绍如何清理 Docker 垃圾的常见方法。

docker prune

你可以通过原生的多种 prune 命令来清理垃圾,比如

docker image prune # 清理镜像
docker container prune # 清理容器
docker volume prune # 清理卷
docker builder prune # 清理构建缓存

当然还有终极杀招

docker system prune # 清理所有

针对构建缓存还有更好的办法

那么可以尝试 builder 的 GC,这样就不会在本地保留构建太多缓存了。

你可以通过修改 docker deamon 的配置文件来开启这个功能

{
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "10GB",
"policy": [
{ "keepStorage": "10GB", "filter": ["unused-for=2200h"] },
{ "keepStorage": "50GB", "filter": ["unused-for=3300h"] },
{ "keepStorage": "100GB", "all": true }
]
}
}
}

通过这些方法,你可以清理掉你的电脑上的大量 Docker 垃圾。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK