-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun_docker.sh
52 lines (41 loc) · 1.1 KB
/
run_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
#!/bin/bash
container=test
image=maxdiff
port=6080
url="http://localhost:$port"
cleanup() {
docker stop $container >/dev/null
docker rm $container >/dev/null
}
image_found=$(docker images -q ${image})
if [ -z "$image_found" ]; then
echo "Building image..."
docker build -t $image --label latest .
echo " "
fi
running=$(docker ps -a -q --filter "name=${container}")
if [ -n "$running" ]; then
echo "Stopping and removing the previous session..."
cleanup
fi
echo "Setting up the graphical application container..."
echo "Point your web browser to ${url}"
echo "When ready to end docker session, close terminal"
docker run \
-d \
--name $container \
-v docker_test_results:/home/user/work/results \
-p $port:6080 \
--env "APP=xterm" \
$image >/dev/null
print_app_output() {
docker cp $container:/var/log/supervisor/graphical-app-launcher.log - \
| tar xO
result=$(docker cp $container:/tmp/graphical-app.return_code - \
| tar xO)
cleanup
}
trap "docker stop $container >/dev/null && print_app_output" SIGINT SIGTERM
docker wait $container >/dev/null
print_app_output
echo "Shutdown complete"