-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·70 lines (51 loc) · 1.6 KB
/
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
#!/bin/bash
#parameters
containerName="tensorflowdocker"
imageName="tensorflow"
imageTag=docker
src_folder=$(pwd)/src/
data_folder=$(pwd)/data/
# Check data directory
if [ -d "$data_folder" ];
then
echo "$data_folder directory exists."
else
echo "$data_folder directory does not exist."
mkdir -p $data_folder
fi
#for gpu access
#xhost local:root has security risks.
xhost local:root
XAUTH=/tmp/.docker.xauth
YEL='\033[0;33m'
NC='\033[0m' # No Color
#Set permissions for newly created files. All new files will have the following permissions.
#Important is that the group permissions of the files created are set to read and write.
#We add src as a volume, so we will be able to edit and delete the files created in the container.
#Output of this command is silenced
setfacl -PRdm u::rwx,g::rwx,o::r ./ &> /dev/null
# container remove
if docker ps | grep -q "$containerName"; then
echo -e "${YEL}stopping ${containerName}${NC}"
docker stop "$containerName"
fi
if docker ps -a | grep -q "$containerName"; then
echo -e "${YEL}removing ${containerName}${NC}"
docker rm "$containerName"
fi
echo "Creating new $containerName container."
docker run -d \
--env DISPLAY=${DISPLAY} \
--env="QT_X11_NO_MITSHM=1" \
--env="XAUTHORITY=$XAUTH" \
--device=/dev/dri:/dev/dri \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--volume $data_folder:/home/appuser/data/ \
--volume $src_folder:/home/appuser/src/ \
--volume="$XAUTH:$XAUTH" \
--network host \
--gpus all \
--runtime=nvidia \
--name="$containerName" \
"$imageName":"$imageTag"
echo "Hello $USER"