Skip to content

Instantly share code, notes, and snippets.

@dpwrussell
Created November 8, 2019 12:36
Show Gist options
  • Save dpwrussell/fb8182f1eec3827e92666022d3390cd1 to your computer and use it in GitHub Desktop.
Save dpwrussell/fb8182f1eec3827e92666022d3390cd1 to your computer and use it in GitHub Desktop.
Docker x-forwarding experiment
# X-Forwarding experiment to run graphical applications inside Docker without host UID specific image/container
Usage:
```bash
# Builds "xforward" docker image
./run.sh
# Then from inside the running container
xclock
```
Note: Linux only. This used to work on mac, but potentially the Mojave upgrade has broken it.
FROM ubuntu
RUN apt-get -y update \
&& apt-get -y install xauth \
&& apt-get -y install libxt6 libxtst6 libgtk2.0-0 libnss3 libx11-xcb1 libxss1 libasound2 \
&& apt-get -y install x11-apps \
&& rm -rf /var/lib/apt/lists/*
#!/usr/bin/env bash
set -e
# X-Forwarding setup
# Note: If sshing into the Docker, this requires that the Docker host's sshd
# config is using: X11UseLocalhost no
XAUTH="/tmp/.docker.xauth"
HOSTNAME=$(hostname)
MAGIC_COOKIE=$(xauth list | grep ${HOSTNAME} | grep -v 'unix:' | awk '{print $3}' | tail -n 1)
DISPLAYPORT=$(echo ${DISPLAY} | cut -d ":" -f 2)
IP=$(docker network inspect bridge | jq -r '.[0].IPAM.Config[0].Gateway')
xauth -f ${XAUTH} add ${IP}:${DISPLAYPORT} . ${MAGIC_COOKIE}
docker build -t xforward .
docker run \
-it \
--rm \
-v ${XAUTH}:${XAUTH} \
-v /tmp/tokens/:/tmp/tokens \
-e DISPLAY="${IP}:${DISPLAYPORT}" \
-e XAUTHORITY=$XAUTH \
xforward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment