__director

镜像清理

#!/usr/bin/env bash
#Author: 原件
#Data: 2020/12/30
#Description: 清理无标签的镜像,保留每个镜像最新的5个tag。

docker system prune -f

docker images | awk '{print $1}' | awk '{a[$1]++} END {for(i in a) if(a[i]>5) print(i"-"a[i])}' > /tmp/image-clear

for s in `cat /tmp/image-clear`;do

docker images | awk '$1=="'${s%-*}'"{print $0}' | tac | sed -n 1,`expr ${s##*-} - 5`p | awk '{print $3}' | uniq > /tmp/image-id

docker rmi -f `cat /tmp/image-id`

done

echo "****************"
echo "clear successful"
echo "****************"

posted on 2021-02-22 20:00  __director  阅读(43)  评论(0编辑  收藏  举报

导航