-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·62 lines (53 loc) · 1.7 KB
/
start.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
#!/usr/bin/env bash
#
# Start docker environment
#
# Options (first only):
# --build ... start with new build images
# --update ... start with updated base images
# --reset ... fresh start with removed containers, images and networks
# --reset-all ... fresh start with removed containers, images, networks and volumes
# Options (second only):
# --no-start ... run script with no Docker start
# Clean up notes:
# sudo docker system prune --all
# sudo docker system prune --all --volumes
# cd & check
if ! cd "$(dirname "$0")"; then exit; fi
# Need root for Linux
if [[ "$(uname -s)" == "Linux" && "$(id -u)" -ne 0 ]]; then
printf "Please run this script as root\nsudo %s\n" "$0" >&2
exit 1
fi
# Remove containers, images, networks and
# with argument 'all' also volumes
reset() {
echo "This removes containers, images and networks!"
[[ $1 == "all" ]] && echo "This also removes volumes. Important data can be lost!"
read -p "Are you sure you want to continue? [y/N] " -r -n 1 answer
echo ""
[[ "$answer" != "y" && "$answer" != "Y" ]] && exit 0
if [[ $1 == "all" ]]; then
docker compose down --rmi all --volumes --remove-orphans
else
docker compose down --rmi all --remove-orphans
fi
}
# Parse script options
if [[ "$1" == "--build" ]]; then
# Build images
docker compose build
elif [[ "$1" == "--update" ]]; then
# Pull newer images and build images
docker compose build --pull
elif [[ "$1" == "--reset" ]]; then
# Remove containers, images and networks
reset
elif [[ "$1" == "--reset-all" ]]; then
# Remove containers, images, networks and volumes
reset all
fi
# Exit without start
[[ "$2" == "--no-start" ]] && exit 0
# Start docker environment
docker compose up -d