-
Notifications
You must be signed in to change notification settings - Fork 37
/
run.bash
executable file
·107 lines (95 loc) · 2.77 KB
/
run.bash
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
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
#
# Copyright (C) 2018 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Runs a docker container with the image created by build.bash
# Requires:
# docker
# nvidia-docker
# an X server
# Recommended:
# A joystick mounted to /dev/input/js0 or /dev/input/js1
if [ $# -lt 1 ]
then
echo "Usage: $0 <docker image> [<dir with workspace> ...]"
exit 1
fi
#IMG=$(basename $1)
IMG=$1
ARGS=("$@")
# Make sure processes in the container can connect to the x server
# Necessary so gazebo can create a context for OpenGL rendering (even headless)
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist $DISPLAY)
xauth_list=$(sed -e 's/^..../ffff/' <<< "$xauth_list")
if [ ! -z "$xauth_list" ]
then
echo "$xauth_list" | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
DOCKER_OPTS=
# Get the current version of docker-ce
# Strip leading stuff before the version number so it can be compared
DOCKER_VER=$(dpkg-query -f='${Version}' --show docker-ce | sed 's/[0-9]://')
if dpkg --compare-versions 19.03 gt "$DOCKER_VER"
then
echo "Docker version is less than 19.03, using nvidia-docker2 runtime"
if ! dpkg --list | grep nvidia-docker2
then
echo "Please either update docker-ce to a version greater than 19.03 or install nvidia-docker2"
exit 1
fi
DOCKER_OPTS="$DOCKER_OPTS --runtime=nvidia"
else
DOCKER_OPTS="$DOCKER_OPTS --gpus all"
fi
# Share your vim settings.
VIMRC=~/.vimrc
if [ -f $VIMRC ]
then
DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro"
fi
# Prevent executing "docker run" when xauth failed.
if [ ! -f $XAUTH ]
then
echo "[$XAUTH] was not properly created. Exiting..."
exit 1
fi
# Mount extra volumes if needed.
# E.g.:
# -v "/opt/sublime_text:/opt/sublime_text" \
# Developer note: If you are running docker in cloudsim then make sure to add
# -e IGN_PARTITION=subt to the following command.
docker run -it \
-e DISPLAY \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTH \
-v "$XAUTH:$XAUTH" \
-v "/tmp/.X11-unix:/tmp/.X11-unix" \
-v "/etc/localtime:/etc/localtime:ro" \
-v "/dev/input:/dev/input" \
--network host \
--rm \
--privileged \
--security-opt seccomp=unconfined \
$DOCKER_OPTS \
$IMG \
${@:2}