#!/usr/bin/env bash
####删除docker镜像,每一个镜像都会保留最新的20个镜像,其余的删除。
export image_name_list=`docker images | awk '{print $1}' | sed '1d' | sort -u`
for vv in ${image_name_list[@]};do
echo ++++++++++++ begin to delete $vv +++++++++++++++++++
export name=$vv
images_list=`echo $passwd | sudo -S docker images | grep $name | awk '{print ENVIRON["name"]":"$2}' | sed '1,20d' | tr '\n' ' '`
docker rmi $images_list
done