This repository was archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_x11
More file actions
executable file
·63 lines (52 loc) · 1.73 KB
/
docker_x11
File metadata and controls
executable file
·63 lines (52 loc) · 1.73 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
#!/bin/bash
# Get Inputs
DOCKER_IMAGE=${@}
# Check Environment
if [ $(uname) == 'Linux' ]; then
echo "Detected Host System: Linux"
# Setup xauth file location; Remove if exists
echo "Setting up X11 forwarding for User: ${USER}"
XTEMP=/tmp/.docker.xauth.${USER}
if [ -e ${XTEMP} ]; then
rm -f ${XTEMP}
fi
# Create new xauth file
touch ${XTEMP}
# modify xauth file
xauth nlist $(hostname)/unix:${DISPLAY:1:1} | sed -e 's/^..../ffff/' | xauth -f ${XTEMP} nmerge -
# Run docker
echo "Running Image..."
docker run -it --rm \
-e DISPLAY=${DISPLAY} \
-e QT_X11_NO_MITSHM=1 \
-v ${XTEMP}:${XTEMP} \
-e XAUTHORITY=${XTEMP} \
--device=/dev/dri:/dev/dri \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--net=host \
-v $(echo ${HOME}):/home \
${DOCKER_IMAGE[*]}
# Clean up auth file when done
if [ -e ${XTEMP} ]; then
rm -f ${TEMP}
fi
elif [ $(uname) == 'Darwin' ]; then
echo "Detected Host System: macOS"
echo "Running Docker with X11 requires XQuartz."
echo "The 'Allow connections from network clients' must also be enabled."
echo "This can be found under XQuartz-->Preferences-->Security."
echo "You must also enable indirect GLX. You can do this with the following terminal command:"
echo " defaults write org.macosforge.xquartz.X11 enable_iglx -bool true"
# Open Xquartz
echo "Opening XQuartz..."
# Add IP to xhost
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + ${IP}
# Get display number
DISPLAY_NUM=`ps -ef | grep "Xquartz :\d" | grep -v xinit | awk '{ print $9; }'`
docker run -it --rm --privileged \
-e DISPLAY=${IP}${DISPLAY_NUM} \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $(echo ${HOME}):/home \
${DOCKER_IMAGE[*]}
fi