docker 定时清理none镜像

===============================================html

 2019/3/31_第1次修改                       ccb_warlockdocker

 

===============================================shell

因为经过jenkins生成的docker标记为lastest,故更新服务器拉取新镜像后,会出现多个已经不使用的旧镜像的标记为none。centos

经过手工清理这些镜像费时费力,故本记录使用定时脚本删除标记为none的镜像。(这样每次更新完以后我不须要再去考虑手工清理镜像,轻松多了)bash

 

前提:服务器

1. docker部署在centos7上;centos7

 


1、建立删除none的shell脚本

1.1 建立clear.sh

# 编辑clear.shspa

vi /opt/clear.sh

将下面的内容添加到clearnoneimages.sh文件中,wq保存。rest

docker images|grep none|awk '{print $3}'|xargs docker rmi

 

1.2 给该shell脚本增长可执行权限

chmod 777 /opt/clear.sh

 


2、增长定时任务

2.1 编辑crontab

vi /etc/crontab

将下面的内容添加到crontab文件中,wq保存。code

# 天天1:00执行该脚本
0 1 * * * root bash /opt/clear.sh

 

2.2 重启crontab

systemctl restart crond

 


参考文档:

1.http://www.javashuo.com/article/p-fusxhefu-hw.html

相关文章
相关标签/搜索