-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup_docker.sh
More file actions
executable file
·49 lines (38 loc) · 1.41 KB
/
cleanup_docker.sh
File metadata and controls
executable file
·49 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -e
############################################################
# Docker Environment Cleanup Script
# ---------------------------------
# This script removes all Docker images, containers,
# volumes, networks, and build caches.
# Use it before re-testing or rebuilding your pipeline
# from a clean state.
############################################################
echo "=========================================="
echo " Docker Cleanup Utility"
echo "=========================================="
echo
read -p "⚠️ WARNING: This will remove ALL Docker data (containers, images, volumes, cache). Continue? (y/N): " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
echo "Aborted."
exit 0
fi
echo
echo "Stopping all running containers..."
docker stop $(docker ps -aq) 2>/dev/null || true
echo "Removing all containers..."
docker rm -f $(docker ps -aq) 2>/dev/null || true
echo "Removing all images..."
docker rmi -f $(docker images -aq) 2>/dev/null || true
echo "Removing all volumes..."
docker volume rm $(docker volume ls -q) 2>/dev/null || true
echo "Removing all user-created networks..."
docker network rm $(docker network ls -q | grep -v "bridge\|host\|none") 2>/dev/null || true
echo "Pruning builder cache..."
docker builder prune -af
echo "Running full system prune..."
docker system prune -af --volumes
echo
echo "✅ Docker environment successfully cleaned."
echo
docker system df