Skip to content

Docker 清理构建缓存

核心清理命令

shell
# 删除所有未被引用的构建缓存层。-f 表示强制执行,无需二次确认
docker builder prune -f

# 删除以下资源:
#    停止的容器
#    未被容器使用的网络
#    无标签镜像(包括 Build 缓存)
#    未被使用的数据卷
docker system prune -a --volumes -f

进阶清理策略

按时间保留缓存

shell
docker builder prune --filter "until=240h" -f

磁盘空间管理

shell
# 查看缓存占用
docker system df