-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_container.sh
More file actions
executable file
·98 lines (81 loc) · 3.37 KB
/
Copy pathcreate_container.sh
File metadata and controls
executable file
·98 lines (81 loc) · 3.37 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
CONTAINER_NAME=dynamic_slam_coords
CONTAINER_IMAGE_NAME=dynamic_slam_coords
### EDIT THIS TO WHEREVER YOU'RE STORING YOU DATA ###
# folder should exist before you mount it
LOCAL_DATA_FOLDER=/media/jmor6670/T7/datasets
LOCAL_RESULTS_FOLDER=~/results/
LOCAL_VDO_SAM_FOLDER=~/Code/src/dynamic_slam_coordinates
CONTAINER_DATA_FOLDER=/root/data
CONTAINER_RESULTS_FOLDER=/root/results
CONTAINER_WORKSPACE_FOLDER=/root/dynamic_slam_coordinates
USE_NVIDIA=false
# If we are running in a docker-in-docker scenario NVIDIA_SOS will be populated
# and we dont need to check for gpu or roscore
if [ -z "$NVIDIA_SOS" ]; then
# Is there an nvidia card in the system?
if [[ $(lshw -C display 2> /dev/null | grep -i NVIDIA) ]]; then
echo "Nvidia GPU in the system, trying to use it."
# If we have nvidia-container-runtime...
if nvidia-container-runtime -v > /dev/null; then
# Check if we have an nvidia driver
NVIDIA_DRIVER_VERSION=`nvidia-smi --query-gpu=driver_version --format=csv,noheader | awk '{ print substr($0, 0, 4) }'`
if [ -z "$NVIDIA_DRIVER_VERSION" ]; then
echo "No Nvidia driver version found, but nvidia-container-runtime is installed... can you run 'nvidia-smi?"
echo "You may want to install a driver to take advantage of it."
else
USE_NVIDIA=true
fi
else
echo "Warning:"
echo "The system has a Nvidia GPU but doesn't have nvidia-container-runtime installed"
echo "You may want to install it to take advantage of it, e.g.:"
echo "sudo apt-get install nvidia-container-runtime"
fi
if ! "$USE_NVIDIA"; then
echo "Using non-nvidia alternative."
fi
fi
else
USE_NVIDIA=true
DOCKER_IN_DOCKER=true
fi
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
echo "Mounting data folder (local) $LOCAL_DATA_FOLDER -> (container) $CONTAINER_DATA_FOLDER"
if [ -z "$NVIDIA_SOS" ]; then
# This provides a list of all .so files installed from packages from 'nvidia-''
NVIDIA_SOS=$(dpkg -l | grep nvidia- | awk '{print $2}' | xargs dpkg-query -L | grep lib | grep .so)
# This generates --volume /path/to/.so:/path/to/.so lines for every .so
fi
for so in $NVIDIA_SOS; do DOCKER_NVIDIA_SO_VOLUMES+="--volume $so:$so "; done
if "$USE_NVIDIA"; then
# We can't use "-i"
if [ -t 1 ]; then
TERMINAL_FLAGS='-it'
else
TERMINAL_FLAGS='-t'
fi
# Create the container based on the launchfile it's launching (if any)
# removes '.launch' from the last argument
echo "Container name will be: $CONTAINER_NAME"
docker run $DOCKER_NVIDIA_SO_VOLUMES \
--privileged \
-i -d --gpus all \
--volume $XSOCK:$XSOCK:rw \
-v $LOCAL_DATA_FOLDER:$CONTAINER_DATA_FOLDER \
-v $LOCAL_RESULTS_FOLDER:$CONTAINER_RESULTS_FOLDER \
-v $LOCAL_VDO_SAM_FOLDER:$CONTAINER_WORKSPACE_FOLDER \
-v /var/run/docker.sock:/var/run/docker.sock \
--env DISPLAY=$DISPLAY \
--env XAUTHORITY=$XAUTH \
--env QT_X11_NO_MITSHM=0 \
--env QT_X11_NO_XRENDER=0 \
--volume $XAUTH:$XAUTH:rw \
--net host \
--pid host \
-it \
--name=$CONTAINER_NAME \
$CONTAINER_IMAGE_NAME "$@"
fi
xhost +local:`docker inspect --format='{{ .Config.Hostname }}' $CONTAINER_NAME`