-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool-docker.sh
executable file
·111 lines (91 loc) · 2.34 KB
/
tool-docker.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
help_list() {
echo "[USAGE] :
${0##*/} [-h] [OPTIONS]
[OPTIONS] :
all : Remove every docker images, containers, volumes...etc
image : Remove every docker images
container : Remove every docker containers
volume : Remove every docker volumes
prune : Remove every dangling resources
list : List active containers on the current machine
"
}
RESET='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTGRAY='\033[0;37m'
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
LIGHTPURPLE='\033[1;35m'
LIGHTCYAN='\033[1;36m'
WHITE='\033[1;37m'
parse_options() {
case $@ in
-h|help)
help_list
exit
;;
all)
remove_all
;;
image)
remove_images
;;
container)
remove_containers
;;
prune)
remove_prune
;;
list)
list_active_containers
;;
volume)
remove_volumes
;;
*)
echo "Unknown option: ${opt} Run ${0##*/} -h for help.">&2
exit 1
esac
}
remove_all() {
echo -e "${RED}[REMOVING]${RESET} Every images, containers and volumes : "
echo -e "${LIGHTCYAN}[IMAGES]${RESET}" && sudo docker image prune -f
echo -e "${LIGHTCYAN}[CONTAINERS]${RESET}" && sudo docker container prune -f
echo -e "${LIGHTCYAN}[DANGLING RESOURCES]${RESET}" && sudo docker system prune -f
echo -e "${LIGHTCYAN}[VOLUMES]${RESET}" && sudo docker volume prune -f
echo -e "${LIGHTGREEN}[SUCCESS]${RESET} removing"
}
remove_images() {
echo -e "${RED}[REMOVING]${RESET} Every images "
sudo docker image prune -f
echo -e "${LIGHTGREEN}[SUCCESS]${RESET} removing"
}
remove_containers() {
echo -e "${RED}[REMOVING]${RESET} Every stopped containers "
sudo docker container prune -f
echo -e "${LIGHTGREEN}[SUCCESS]${RESET} removing"
}
remove_prune() {
echo -e "${RED}[REMOVING]${RESET} Every dangling resources "
sudo docker system prune -f
echo -e "${LIGHTGREEN}[SUCCESS]${RESET} removing"
}
remove_volumes() {
echo -e "${RED}[REMOVING]${RESET} Every unused volumes "
sudo docker volume prune -f
echo -e "${LIGHTGREEN}[SUCCESS]${RESET} removing"
}
list_active_containers() {
echo -e "${LIGHTCYAN}[INFO]${RESET} Every running containers :"
sudo docker ps
}
parse_options "$@"