#!/bin/bash
# "awk ‘{print $3}‘"取第三列,"sed -n ‘2,$p‘"取第二行到最后一行, "sort -k2n xx.txt | uniq"排序并去重
image_id_arr=$(docker images | awk ‘{print $3}‘ | sed -n ‘2,$p‘ | sort -k2n xx.txt | uniq)
for val in $image_id_arr
do
docker rmi -f $val
if [ $? -ne 0 ]; then
echo "failed to remove images:["$val"], skipped and remove next one!"
continue;
fi
done;
原文:https://www.cnblogs.com/kribee/p/14501273.html