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
|
2024-09-26 16:20:14 +08:00
|
|
|
echo "要停止的镜像序号,多个镜像用 空格 隔开"
|
2024-09-26 10:53:51 +08:00
|
|
|
read -p "请输入:" pick
|
|
|
|
for i in $pick ; do
|
2024-09-26 16:03:53 +08:00
|
|
|
if [[ $i =~ [1-$docker_number] ]]; then
|
2024-09-26 16:20:14 +08:00
|
|
|
docker stop "${docker_arr[$(( i -1 ))]}"
|
2024-09-26 10:53:51 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
'3')
|
|
|
|
docker system prune -af
|
|
|
|
echo "清理完成"
|
|
|
|
esac
|