-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.sh
executable file
·76 lines (66 loc) · 1.37 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
#!/bin/bash
IMAGEID="opencv:latest"
# set xorg access on host
xhost +local:docker
ABS_PATH="$(pwd)"
function setup_image()
{
docker build -t $IMAGEID .
}
function start_container()
{
CID=$(docker create \
-e DISPLAY=:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /root/.Xauthority:/root/.Xauthority:rw \
-v $ABS_PATH:/root \
-i $IMAGEID)
docker rename $CID landsat
docker start $CID
docker exec -it $CID /bin/bash
echo "Container started. ID:landsat"
}
function start_temp_container()
{
docker run -it --rm \
-e DISPLAY=:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /root/.Xauthority:/root/.Xauthority:rw \
-v $ABS_PATH:/root \
$IMAGEID
}
function stop_container()
{
docker ps | grep landsat
docker stop landsat
docker rm landsat
}
# ------------- ARG PARSER ----------- #
while [[ $# -gt 0 ]]
do
action="$1"
case $action in
setup)
echo -e "\n--------- Build Docker Image ---------\n"
setup_image
shift
;;
start)
echo -e "\n--------- Start container ---------\n"
start_container
shift
;;
run)
start_temp_container
shift
;;
stop)
stop_container
shift
;;
*)
echo "Unknown option $action"
exit 1
;;
esac
done