-
Notifications
You must be signed in to change notification settings - Fork 6
/
rebuild.sh
executable file
·49 lines (42 loc) · 1.18 KB
/
rebuild.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
#!/bin/bash
############################################################
#
# A simple script that makes debugging dockerfiles easier.
#
############################################################
set -x
# Name for this container and image
name="bchd-web"
# Check for a -p flag
while [[ "$#" > 0 ]]; do case $1 in
-p|--production) production=true; shift;;
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done
# Choose flag for detached or interactive terminal
if [ "$production" = true ]
then
img_name="zquestz/"$name
container_name=$name
run_mode="-d"
port="-p 5000:80"
restart="--restart always"
else
img_name="zquestz/"$name"-dev"
container_name=$name"-dev"
run_mode="-it"
port="-p 5000:80"
restart=""
mount='type=bind,source='"$(pwd)"'/.build,target=/usr/share/nginx/html/'
fi
# Stop any running containers with this name
docker stop $container_name
docker rm $container_name
# Build the new image
docker build . -t $img_name || exit
# Run the new image
if [ "$production" = true ]
then
docker run $run_mode $port --name $container_name $img_name || exit
else
docker run $run_mode $port --name $container_name --mount "$mount" $img_name || exit
fi