[root@m ~]# docker service update ··· # 更新服务
更新服务镜像后,发现旧的容器没有删除,变为Exited(Exited、Shutdown等)状态,查资料也没有说多久会删除。
(放了两个周也没自动清理),可能旧容器会一直存在,有其它用处。
有文章称保留是为了服务回滚操作。反正看着没啥用,就找删除方法。
在docker版本1.13之后可以用命令清理。
# 查看相关清理命令
[root@m ~]# docker system --help Usage: docker system COMMAND Manage Docker Commands: df Show docker disk usage events Get real time events from the server info Display system-wide information prune Remove unused data
# 清理命令相关参数
[root@m ~]# docker system prune --help Usage: docker system prune [OPTIONS] Remove unused data Options: -a, --all Remove all unused images not just dangling ones --filter filter Provide filter values (e.g. 'label=<key>=<value>') -f, --force Do not prompt for confirmation --volumes Prune volumes
通过 -a 参数可以清理未使用的镜像,-f 强制删除,不提示确认。
# 清理旧容器及不用的镜像
[root@m ~]# docker system prune -a -f
可以添加到任务计划里定时清理,或者是更新完服务测试后没问题通过脚本批量清理。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4503.html