-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-run.sh
executable file
·77 lines (71 loc) · 2.63 KB
/
docker-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
69
70
71
72
73
74
75
76
77
#!/bin/bash
XSOCK=/tmp/.X11-unix
# change the XAUTH to your own .Xauthority file
XAUTH=/root/.Xauthority
DOCKER_REPO=kakalin/
BRAND=qt
VERSION=5.15.10
IMAGE_NAME=${DOCKER_REPO}${BRAND}:${VERSION}
# https://stackoverflow.com/questions/3162385/how-to-split-a-string-in-shell-and-get-the-last-field
PROJECT_FOLDER=${PWD##*/}
GPU_DEVICE=""
if [[ -z $1 ]]; then
GPU_DEVICE="all"
else
GPU_DEVICE="device=$1"
fi
# -e QT_X11_NO_MITSHM=1: Disables MIT-SHM extension for Qt applications.
# -e XAUTHORITY=$XAUTH: Sets the XAUTHORITY environment variable to the .Xauthority file.
# -v $XSOCK:$XSOCK: Mounts the X11 socket to the container.
# -v $HOME/.Xauthority:$XAUTH: Mounts the .Xauthority file to the container.
# --network=host: Shares the host network with the container.
# --privileged: Enables privileged mode for the container.s
docker_run_params=$(cat <<-END
--rm -it \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTH \
-v $XSOCK:$XSOCK \
-v $HOME/.Xauthority:$XAUTH \
--network=host \
-v $PWD:/root/$PROJECT_FOLDER \
-w /root/$PROJECT_FOLDER \
--privileged \
$IMAGE_NAME
END
)
# xhost 開放權限
## on Local machine
xhost +localhost # for macOS
xhost +local:docker # for Linux
## on Remote machine
# xhost + # or xhost +<specific ip>
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
GPU=$(lspci | grep -i '.* vga .* nvidia .*')
if [[ $GPU == *' NVIDIA '* ]]; then
# -e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native: Sets the PulseAudio server environment variable.
# -v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native: Mounts the PulseAudio socket to the container.
# -v $PWD:/home/user/$PROJECT_FOLDER: Mounts the current directory to the container.
docker run \
--gpus $GPU_DEVICE \
-e DISPLAY=$DISPLAY \
-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v ~/.config/pulse/cookie:/root/.config/pulse/cookie \
$docker_run_params
else
docker run \
-e QT_QUICK_BACKEND=software \
-e DISPLAY=$DISPLAY \
-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v ~/.config/pulse/cookie:/root/.config/pulse/cookie \
$docker_run_params
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
docker run \
-e DISPLAY=host.docker.internal:0 \
-e QT_QUICK_BACKEND=software \
$docker_run_params
else
echo "Haven't supported this OS Type, please check command\n and update it."
fi