记一次清理docker文件占用磁盘的问题
公司测试环境是k8s,研发发布项目都是通过jenkins发布的,由于打包机器常年不清理没用的镜像以及缓存,导致docker镜像文件以及缓存文件将磁盘打满了,/var/lib/docker/overlay2目录将100G的磁盘直接干满了。现将清理过程记录如下:
先将机器上所有镜像都干掉
for i in `docker images |egrep "^zw" |awk '{print $1":"$3}'`;do docker rmi $i;done
发现干掉之后磁盘容量还是没有下去
docker system df 查看docker磁盘使用情况 [root@jenkins-node2 docker]# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 0 0 0B 0B Containers 0 0 0B 0B Local Volumes 0 0 0B 0B Build Cache 804 0 99.14GB 99.14GB # 发现构建缓存占用了大多数空间。必须清理 [root@jenkins-node2 docker]# docker builder prune WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] y ID RECLAIMABLE SIZE LAST ACCESSED 009hxbu35s7i7h0osurko3ibb true 10.01MB 6 weeks ago jydyjp3sfq25ytyhzej5i27z0 true 10.01MB 7 weeks ago ptipp5j4alflg48o9sfkcw9b4 true 239.9MB 8 weeks ago ybtd8jmp98497hyseulrlu5at true 5.006MB 4 weeks ago ... ... 0v13j86ighuwafvui2w1l34gj true 0B Less than a second ago Total: 99.14GB
| 类型 | 说明 |
| Images | 所有镜像占用的空间,包括拉取下来的镜像和本地构建的。 |
| Containers | 运行的容器占用的空间,表示每个容器的读写层的空间。 |
| Local Volumes | 容器挂载本地数据卷的空间。 |
| Build Cache | 镜像构建过程中产生的缓存大小。RECLAIMABLE这一列表示可回收的大小。 |
docker builder prune # 一键清理,清理磁盘,删除关闭的容器、无用的数据卷和网络以及无tag的镜像。 docker builder prune --filter 'until=24h' # 保留最近1天的缓存。 docker system prune -a # 清理得更彻底,可将没有容器使用的镜像删掉。

浙公网安备 33010602011771号