linuxtool/Config/Docker/image.sh

31 lines
702 B
Bash
Raw Normal View History

2024-09-26 10:53:51 +08:00
#!/bin/bash
echo "1.查看当前运行中的镜像"
echo "2.停止镜像"
echo "3.删除没有使用的镜像"
declare pick
read -p "请输入:" pick
case $pick in
'1')
docker ps --format "{{.Names}}"
;;
'2')
2024-09-26 16:03:53 +08:00
declare -a docker_arr=($(docker ps --format "{{.Names}}"))
declare docker_number=0
for i in "${docker_arr[@]}" ; do
docker_number=$(( docker_number+1 ))
echo "${docker_number}.${i}"
2024-09-26 10:53:51 +08:00
done
echo "要删除的镜像序号,多个镜像用 空格 隔开"
read -p "请输入:" pick
for i in $pick ; do
2024-09-26 16:03:53 +08:00
if [[ $i =~ [1-$docker_number] ]]; then
docker rmi "${docker_arr[$i]}"
2024-09-26 10:53:51 +08:00
fi
done
;;
'3')
docker system prune -af
echo "清理完成"
esac