使用 df 命令查看磁盘的使用情况:
docker system df
返回的结果如下:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 70 8 6.188GB 5.196GB (83%)
Containers 8 1 200.9MB 0B (0%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
Docker采用保守的方法来清理未使用的对象(通常称为“垃圾回收”),通常不会自动删除镜像、容器、卷和网络这些对象。可以使用prune修剪。
#清理未使用的镜像
docker image prune。
#清理无用的数据卷
docker volume prune
#清理未使用的网络
docker network prune
#清理Docker缓存
docker builder prune
#清理Docker日志
truncate -s 0 <logfile>。
#一次清理多种类型的对象
docker system prune
清理所有无容器使用的镜像可以加上-a
或者--all
docker network prune --all
默认情况下,系统会提示是否继续。
Are you sure you want to continue? [y/N]
要绕过提示,可以使用 -f 或 --force。
docker image prune --force
可以使用 --filter 标志使用过滤表达式来限制修剪哪些镜像。
例如,只考虑 24 小时前创建的镜像:
docker image prune -a --filter "until=24h"
另外,删除所有名字中带 “none” 关键字的镜像
docker rmi $(docker images | grep "none" | awk '{print $3}')
K8s谨慎试用