Skip to content

Instantly share code, notes, and snippets.

@pedroarthur
Created October 9, 2019 15:53
Show Gist options
  • Save pedroarthur/59043a11c3359d405667a0508bba8768 to your computer and use it in GitHub Desktop.
Save pedroarthur/59043a11c3359d405667a0508bba8768 to your computer and use it in GitHub Desktop.
Bash script to run a X application in Docker
#!/bin/bash
USER_ID=$(id -u "$(whoami)")
GROUP_ID=$(id -g "$(whoami)")
XSOCK=/tmp/.X11-unix
XAUTH=$(mktemp /tmp/docker.xauth.XXXX)
trap 'rm $XAUTH; ' EXIT
xauth nlist "$DISPLAY" \
| sed -e 's/^..../ffff/' \
| xauth -f "$XAUTH" nmerge -
docker run \
--env QT_X11_NO_MITSHM=1 \
--env DISPLAY="unix${DISPLAY}" \
--env XAUTHORITY="${XAUTH}" \
--user "${USER_ID}:${GROUP_ID}" \
--volume "$XSOCK:$XSOCK:rw" \
--volume "$XAUTH:$XAUTH:rw" \
"${@}" \
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment