-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.sh
More file actions
executable file
·100 lines (85 loc) · 2.32 KB
/
proxy.sh
File metadata and controls
executable file
·100 lines (85 loc) · 2.32 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
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
#!/bin/bash
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
options=$(getopt -o c:r:h --long config:,root:,help -- "$@")
eval set -- "$options"
image="nginx:stable-alpine-slim"
container_name="nginx-proxy"
network_name="nginx-net"
# Default values
config="$(realpath -e "$(dirname "$0")/nginx.conf")"
root="$(realpath -e "$(dirname "$0")/www")"
parse_options() {
while true; do
case "$1" in
-c | --config)
config="$(realpath -e "$2")"
shift 2
;;
-r | --root)
root="$(realpath -e "$2")"
shift 2
;;
-h | --help)
echo "Usage: $0 [options]"
echo
echo "Options:"
echo " -h, --help Display this help message"
echo " -c, --config <file> Path to the nginx configuration file"
echo " -r, --root <dir> Path to the static directory"
exit
;;
--)
shift
break
;;
*)
exit 1
;;
esac
done
}
parse_options "$@"
echo
echo -e "config file: ${config}"
echo -e "static directory: ${root}"
start() {
echo
echo -e "Starting proxy"
echo
echo -e " using image: ${image}"
echo -e " container name: ${container_name}"
echo -e " network name: ${network_name}"
echo
echo -e "Creating network: ${network_name}"
docker network create ${network_name}
echo
echo -e "Starting container: ${container_name}"
docker run \
--pull "always" \
--rm \
--detach \
--name "${container_name}" \
--network "${network_name}" \
--publish 80:80 \
--volume "${config}":/etc/nginx/nginx.conf:ro \
--volume "${root}":/www:ro \
"${image}"
echo
echo -e "Proxy started"
echo
}
stop() {
echo
echo -e "Stopping proxy"
echo
echo -e "Stopping container"
docker kill ${container_name} || true # allow the script to continue even if the container is not running
echo
echo -e "Removing network"
docker network rm ${network_name}
}
trap 'stop' EXIT # automatically stop container on exit (e.g. CTRL+C)
start
sleep infinity # keep running until CTRL+C