-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_container.sh
executable file
·47 lines (35 loc) · 1.47 KB
/
start_container.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
#!/usr/bin/env bash
IMAGE_NAME="gift_recommender_service"
ROOT="$( pwd )"
npm install
if [[ "$(docker images -q ${IMAGE_NAME}:latest 2> /dev/null)" == "" ]]; then
echo " ----- Image Does Not Exist. Building Now. -----"
docker build -t ${IMAGE_NAME} ${ROOT}
else
echo " ----- Image Available for Use. -----"
fi
PROJECT_NAME="gift_recommender"
CURRENT_DOCKER_COMPOSE_VERSION=$( docker-compose -v | grep -o '[0-9]*[.][0-9]*[.][0-9]' | sed -e 's/[.]//g' )
BREAKING_DOCKER_COMPOSE_VERSION=1210
# Since docker compose version: '1.21.0', the network setup automatically adds a single '_' to the network_name_prefix,
# while version '1.20.0' and below replaces any extra ‘_’ at the end of the network_name_prefix with a single '_'.
# This assumes that at versions below '1.20.0' e.g. '1.9.0', no ‘_’ is added at the end of the network_name_prefix.
if [[ ${CURRENT_DOCKER_COMPOSE_VERSION} -lt ${BREAKING_DOCKER_COMPOSE_VERSION} ]]; then
PROJECT_NAME="${PROJECT_NAME}_"
fi
echo " ----- Network name prefix is: ${PROJECT_NAME} -----"
echo " ----- Starting Up Infrastructure Containers -----"
docker-compose -p ${PROJECT_NAME} up -d
echo " ----- Run Application in a Disposable Container -----"
docker run \
-i \
-t \
-p 32900:8080 \
--rm \
-v ${ROOT}:/src \
--env-file=${ROOT}/.env \
--network=gift_recommender_main_network \
${IMAGE_NAME} \
bash
echo " ----- EXITED from Disposable Container -----"
echo " ----- REMOVED Exited Container -----"