释放双眼,带上耳机,听听看~!
1、docker容器镜像清理脚本,采用docker容器ID方式清理
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash set -e mkdir /opt/dockerimages cd /opt/dockerimages docker images > docker-images.log cat docker-images.log |grep -v "test" |grep -v "hour" | grep -v "days ago" |awk -F ' ' '{print $3}' > docker-images1.log images=$(cat docker-images1.log ) for imageName in ${images[@]} ; do /bin/docker rmi $imageName echo "docker rmi $imageName" done |
2、docker容器镜像清理脚本,采用docker容器镜像名方式清理
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash set -e mkdir /opt/dockerimages cd /opt/dockerimages /bin/docker images > docker-iamges.log cat docker-iamges.log |grep "GB" > docker-iamges1.log cat docker-iamges.log |grep "MB" >> docker-iamges1.log cat docker-iamges1.log |grep "hub.selinux.cn" |grep -v "none"|grep -v "test" |grep -v "hour" | grep -v "days ago" |awk -F ' ' '{print $1 ":" $2}' > docker-iamges2.log images=$(cat docker-iamges2.log ) for imageName in ${images[@]} ; do /bin/docker rmi $imageName echo "docker rmi $imageName" done |
如果大家还有其他好的建议和想法,欢迎留言!
欢迎加入运维交流QQ群:7652650(快捷运维)