批量删除没用的docker镜像、container、volume脚本

TrumanWong
11/2/2022
TrumanWong

脚本del_docker_images.sh

#!/bin/bash
imageIds=$(docker images | awk '{print $3}' | sed -n '2,$p' | sort -k2n | uniq)
for imageId in $imageIds
do
	docker rmi $imageId
	if [ $? -ne 0 ]; then
		echo "failed to remove image:["$imageId"], skipped and remove next one"
	fi
done;

docker system prune -a
docker volume prune

用法:

$ bash del_docker_images.sh