-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-clean
More file actions
executable file
·39 lines (33 loc) · 1.08 KB
/
docker-clean
File metadata and controls
executable file
·39 lines (33 loc) · 1.08 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
#!/bin/sh
echo 'Running `docker system prune`'
docker system prune
exit $?
# This script is no longer necessary
if docker ps --all --format table | grep -q 'Exited\|Created'; then
echo "Removing stopped containers..."
docker ps --all --format table | awk '/Exited|Created/{print $1}' | xargs docker rm
else
echo "No stopped containers to remove."
fi
if docker image ls --format table | grep -q '<none>'; then
echo "Removing dangling images..."
docker image ls --format table \
| awk '/<none>/{print $3}' \
| xargs docker rmi
fi
if docker volume ls --format table | grep -q 'local'; then
echo "Removing dangling volumes..."
docker volume ls --format table \
| awk '/local/{print $2}' \
| xargs docker volume rm
else
echo "No dangling volumes to remove."
fi
if docker network ls --format table | grep -q 'bridge\|host\|none'; then
echo "Removing dangling networks..."
docker network ls --format table \
| awk '/bridge|host|none/{print $1}' \
| xargs docker network rm
else
echo "No dangling networks to remove."
fi