1. 全部清理
该清理包括:容器、网络、镜像、cache
| [root@das-meeting-16 ~]# docker system prune |
| WARNING! This will remove: |
| - all stopped containers |
| - all networks not used by at least one container |
| - all dangling images |
| - all build cache |
| Are you sure you want to continue? [y/N] y |
| Deleted Networks: |
| app_kong-net |
| boe-iotgw-server_default |
| |
| Deleted Images: |
| untagged: 10.252.97.57/iot/web@sha256:35f4fc8df4d6aee308f239d7b395435058ed95fa5467220f4a448822423f86eb |
| deleted: sha256:ef73a04f1abb55216af6447bc8823cb30d84e96081cd502ed3a57b36091b05a3 |
| deleted: sha256:034bf5325ec3345d68a1762c3ec1a7404cf48d7b194ac11cd86597908147ab74 |
| untagged: 10.252.96.249:1987/epd/image-studio@sha256:d662b294b43e4277dbbb79efee729c672ba0a7191840a7ebb706cfeac77e77af |
| deleted: sha256:e0b1eb162b0bea4e2564419150891ae624bc4523e43159f64b6b63e0411bc42b |
| deleted: sha256:d61799bda8e52190456503c6bfdfb137bc5a8c563dfc8cbda878bf53cc656fb9 |
如上可知:
| - all stopped containers |
| - all networks not used by at least one container |
| - all dangling images |
| - all build cache |
当然也可以对以上项目分别进行清理
2. 容器清理
| # docker container prune |
| WARNING! This will remove all stopped containers. |
| Are you sure you want to continue? [y/N] y |
- 删除停止指定时间的容器
如:删除停止24h以上的容器
| # docker container prune --filter "until=24h" |
3. 镜像清理
| # docker image prune |
| WARNING! This will remove all dangling images. |
| Are you sure you want to continue? [y/N] y |
说明:dangling 状态为容器名和tag都为空的镜像,如:
| <none> <none> 2122db2ff445 3 weeks ago 49.7MB |
| # docker image prune -a |
| |
| WARNING! This will remove all images without at least one container associated to them. |
| Are you sure you want to continue? [y/N] y |
- 删除指定时间外未被使用过的镜像
如:删除停止24h以上未被使用过angling 状态的镜像
| # docker image prune --filter "until=24h" |
4. 存储卷清理
| # docker volume prune |
| WARNING! This will remove all volumes not used by at least one container. |
| Are you sure you want to continue? [y/N] y |
没看懂!!!这个是从docker volume inspect xxx 命令看到的结果都是null
| docker volume prune --filter "label!=keep" |
5. 网络清理
| # docker network prune |
| WARNING! This will remove all networks not used by at least one container. |
| Are you sure you want to continue? [y/N] y |
| # docker network prune --filter "until=24h" |
6. 日志清理
见文档: 《docker的日志清理》
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了