-
Notifications
You must be signed in to change notification settings - Fork 6
/
docker_run.sh
executable file
·71 lines (58 loc) · 1.56 KB
/
docker_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
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
#!/bin/bash
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
echo "Running Docker Container"
CONTAINER_NAME=icuas24_competition
# Get distro of the built image
distro=$(docker images $CONTAINER_NAME | tail -n1 | awk '{print $2}')
run_args=""
for (( i=1; i<=$#; i++));
do
param="${!i}"
if [ "$param" == "--bionic" ]; then
distro="bionic"
fi
if [ "$param" == "--focal" ]; then
distro="focal"
fi
if [ "$param" == "--focal-nogpu" ]; then
distro="focal-nogpu"
fi
if [ "$param" == "--run-args" ]; then
j=$((i+1))
run_args="${!j}"
fi
done
echo "Running in $distro"
# Check if there is an already running container with the same distro
full_container_name="${CONTAINER_NAME}_${distro}"
running_container="$(docker container ls -al | grep $full_container_name)"
if [ -z "$running_container" ]; then
echo "Running $full_container_name for the first time!"
else
echo "Found an open $full_container_name container. Starting and attaching!"
eval "docker start $full_container_name"
eval "docker attach $full_container_name"
exit 0
fi
# Check if using GPU
gpu_enabled="--gpus all"
if [ "$distro" == "focal-nogpu" ]; then
gpu_enabled=""
fi
run_args="$gpu_enabled $run_args"
docker run \
$run_args \
-it \
--network host \
--privileged \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--env="XAUTHORITY=${XAUTH}" \
--env DISPLAY=$DISPLAY \
--env TERM=xterm-256color \
--name $full_container_name \
icuas24_competition:$distro \
/bin/bash