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. 镜像清理
- 清理dangling 状态的容器
# 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
- 清理挂载卷labe不是keep的卷
没看懂!!!这个是从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
- 删除24小时未被使用的网络
# docker network prune --filter "until=24h"
6. 日志清理
见文档: 《docker的日志清理》