-
Notifications
You must be signed in to change notification settings - Fork 3
/
run-docker.sh
49 lines (39 loc) · 1.22 KB
/
run-docker.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
#!/bin/bash
IMAGE_NAME="darko_ms1_pybullet_throw:python3"
USERNAME=ros2
CONTAINER_NAME=""
GPUS="all"
RUN_FLAGS=()
USER_ID=$(id -u "${USER}")
GROUP_ID=$(id -g "${USER}")
COMMAND_FLAGS+=(--uid "${USER_ID}")
COMMAND_FLAGS+=(--gid "${GROUP_ID}")
RUN_FLAGS+=(--volume=/tmp/.X11-unix:/tmp/.X11-unix:rw)
RUN_FLAGS+=(--device=/dev/dri:/dev/dri)
if [ -z "${CONTAINER_NAME}" ]; then
CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}"
CONTAINER_NAME="${CONTAINER_NAME/:/-}-runtime"
fi
if [ -n "${USERNAME}" ]; then
RUN_FLAGS+=(-u "${USERNAME}")
fi
if [ -n "${GPUS}" ]; then
RUN_FLAGS+=(--gpus "${GPUS}")
RUN_FLAGS+=(--env DISPLAY="${DISPLAY}")
RUN_FLAGS+=(--env NVIDIA_VISIBLE_DEVICES="${NVIDIA_VISIBLE_DEVICES:-all}")
RUN_FLAGS+=(--env NVIDIA_DRIVER_CAPABILITIES="${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics")
fi
xhost +
RUN_FLAGS+=(-e DISPLAY="${DISPLAY}")
RUN_FLAGS+=(-e XAUTHORITY="${XAUTHORITY}")
RUN_FLAGS+=(-v /tmp/.X11-unix:/tmp/.X11-unix:rw)
RUN_FLAGS+=(--device=/dev/dri:/dev/dri)
if [ ${#FWD_ARGS[@]} -gt 0 ]; then
echo "Forwarding additional arguments to docker run command:"
echo "${FWD_ARGS[@]}"
fi
docker run -it --rm \
--net host \
"${RUN_FLAGS[@]}" \
"${FWD_ARGS[@]}" \
"${IMAGE_NAME}" /bin/bash