#!/bin/bash
# 特定容器的名称或ID
EXCLUDED_CONTAINER="ExcludedContainer"
# 获取所有运行的容器,除了特定容器的ID
CONTAINER_IDS=$(docker ps -q)
# 删除所有容器,除了特定容器的ID
for container_id in ${CONTAINER_IDS[@]}
do
if [ "$container_id" != "$EXCLUDED_CONTAINER" ]; then
docker rm -f $container_id > /dev/null
fi
done
echo "All containers deleted except $EXCLUDED_CONTAINER."
文章评论