-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-remove.sh
executable file
·46 lines (39 loc) · 1.09 KB
/
docker-remove.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
#!/bin/bash
# Usage info
show_help() {
cat << EOF
Help:
This will stop and rm container based on -d
docker-stop.sh -d test.com
Usage: ${0##*/} -d DOMAIN
-d DOMAIN Domain name for this site, will also assign to container name
EOF
}
# getopts specific
OPTIND=1 # Reset is necessary if getopts was used previously in the script. It is a good idea to make this local in a function.
while getopts "hd:" opt; do
case "$opt" in
h)
show_help
exit 0
;;
d) DOMAIN=$OPTARG
;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.
if [ -z "$DOMAIN" ]; then
echo -e "\e[1;31m[Required]\e[0m -d option is required to restart / attach docker"
show_help >&2
exit 1
fi
STARTED=`docker ps | grep $DOMAIN`
if [ -n "$STARTED" ]; then
echo "Stop container $DOMAIN ... "
docker exec -it $DOMAIN supervisorctl stop all && docker stop $DOMAIN
echo "Remove container $DOMAIN ... (data still available)"
docker rm $DOMAIN
exit
fi
echo -e "\e[1;31m$DOMAIN not found\e[0m in startted container"
show_help >&2