-
Notifications
You must be signed in to change notification settings - Fork 10
/
run_i.sh
executable file
·43 lines (34 loc) · 1.09 KB
/
run_i.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
#!/usr/bin/env bash
ERROR_PREFIX="ERROR:"
if [[ ! -z `which nvidia-docker` ]]
then
DOCKER_CMD=nvidia-docker
elif [[ ! -z `which docker` ]]
then
echo "WARNING: nvidia-docker not found. Nvidia drivers may not work." >&2
DOCKER_CMD=docker
else
echo "${ERROR_PREFIX} docker or nvidia-docker not found. Aborting." >&2
exit 1
fi
DIRECTORY=$1
if [ ! -d "$DIRECTORY" ]; then
echo "${ERROR_PREFIX} Directory '${DIRECTORY}' doesn't exist. Aborting." >&2
exit 2
fi
image_tag="cig2017_`basename $DIRECTORY`"
container_name=${image_tag}
run_version=0
while [[ ! -z `docker ps --format '{{.Names}}'|grep "^${container_name}$"` ]]
do
echo "WARNING: '${container_name}' is already a running docker container. Trying to run '${image_tag}_${run_version}'."
run_version=$(($run_version+1))
container_name=${image_tag}_${run_version}
done
if [ "`uname`" != "Linux" ]; then
echo "WARNING: GUI forwarding in Docker was tested only on a linux host."
fi
$DOCKER_CMD run --net=host -ti --name ${container_name} \
--env="DISPLAY" --privileged \
--entrypoint /bin/bash \
${image_tag}