-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_run.sh
executable file
·42 lines (33 loc) · 1.22 KB
/
build_run.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
#!/usr/bin/env bash
export dockerImgTag=minah_struture
export dockerCtnName=minah_struture
docker build --tag=$dockerImgTag .
export isBuiltWell=$?
if [[ $isBuiltWell -eq 0 ]]; then
echo "built image $dockerImgTag with cache"
else
echo "error when build image, please try to build --no-cache"
# docker build --tag=$dockerImgTag --no-cache .;
# export isBuiltWell=$?
fi
if [[ $isBuiltWell -eq 0 ]]; then
echo "successfully built $dockerImgTag"
else
echo "fail to build $dockerImgTag"
exit 1
fi
# clean up old container
echo "stop and remove old container $dockerCtnName"
docker stop $dockerCtnName 2>/dev/null;
docker rm $dockerCtnName 2>/dev/null;
echo "preparing envs"
export envFile=config/env.sh # bash script has "export" commands
export dockerRunEnv=config/.env # generated from the envFile with the following "sed" for "docker run"
bash -x $envFile 2>$dockerRunEnv
sed -i'.bak' 's/+ //' ${dockerRunEnv} && sed -i'.bak' '/^export /d' ${dockerRunEnv} && sed -i'.bak' "s/'//g" ${dockerRunEnv}
rm "${dockerRunEnv}.bak"
docker run -dit --name=$dockerCtnName --restart always \
-p 18181:18181 -p 18282:18282 \
--env-file ${dockerRunEnv} \
${dockerImgTag}
echo "done run $dockerCtnName container"