forked from ichayer/sat-solver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
executable file
·81 lines (71 loc) · 1.68 KB
/
docker.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
help (){
printf "Available commands: \n rmi \n rmc \n build \n run \n help \n listcon \n listimg \n"
}
env_up (){
local file_folder="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # https://medium.com/@Aenon/bash-location-of-current-script-76db7fd2e388
if [ -f "$file_folder/.env" ]; then
set -a
source "$file_folder/.env" # https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
set +a
else
printf ".env file not found in project \n"
return 1
fi
}
run (){
if [ ! "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then # https://stackoverflow.com/questions/38576337
docker run --name ${CONTAINER_NAME} -v ${PWD}:/code --security-opt seccomp:unconfined -ti ${IMAGE_NAME}
else
docker start --interactive ${CONTAINER_NAME} # https://stackoverflow.com/questions/34782678
fi
}
build () {
docker build -t ${IMAGE_NAME} .
}
rmc () {
docker rm --force ${CONTAINER_NAME}
}
rmi () {
docker rmi --force ${IMAGE_NAME}
}
list_images () {
docker images
}
list_containers () {
docker container ps -a
}
main () {
env_up
command="$1"
echo "command is <${command}>"
case "${command}" in
"build")
build
;;
"run")
run
;;
"rmc")
rmc
;;
"rmi")
rmi
;;
"listcon")
list_containers
;;
"listimg")
list_images
;;
"help")
help
;;
*)
printf "ERROR: Missing command. \n"
help
exit 1
;;
esac
}
main "$@"