Files
012-kaopeilian/deploy/scripts/cleanup_docker.sh
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

63 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Docker 清理脚本
# 用于清理未使用的Docker资源
echo "🧹 开始清理Docker资源..."
# 1. 清理停止的容器
echo "📋 清理停止的容器..."
stopped_containers=$(docker ps -a --filter "status=exited" -q)
if [ ! -z "$stopped_containers" ]; then
echo "发现停止的容器: $stopped_containers"
docker rm $stopped_containers
echo "✅ 已清理停止的容器"
else
echo "✅ 没有停止的容器需要清理"
fi
# 2. 清理悬空镜像
echo "📋 清理悬空镜像..."
dangling_images=$(docker images --filter "dangling=true" -q)
if [ ! -z "$dangling_images" ]; then
echo "发现悬空镜像: $dangling_images"
docker rmi $dangling_images
echo "✅ 已清理悬空镜像"
else
echo "✅ 没有悬空镜像需要清理"
fi
# 3. 清理未使用的卷
echo "📋 清理未使用的卷..."
unused_volumes=$(docker volume ls --filter "dangling=true" -q)
if [ ! -z "$unused_volumes" ]; then
echo "发现未使用的卷: $unused_volumes"
docker volume rm $unused_volumes
echo "✅ 已清理未使用的卷"
else
echo "✅ 没有未使用的卷需要清理"
fi
# 4. 清理未使用的网络
echo "📋 清理未使用的网络..."
unused_networks=$(docker network ls --filter "dangling=true" -q)
if [ ! -z "$unused_networks" ]; then
echo "发现未使用的网络: $unused_networks"
docker network rm $unused_networks
echo "✅ 已清理未使用的网络"
else
echo "✅ 没有未使用的网络需要清理"
fi
# 5. 显示当前状态
echo "📊 当前Docker状态:"
echo "运行中的容器:"
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
echo -e "\nDocker卷:"
docker volume ls
echo -e "\nDocker网络:"
docker network ls
echo "🎉 Docker清理完成"