Running GUI apps in Docker containers

Dimitris Kapanidis
Jan 4, 2017 · 3 min read
Docker for Mac installation

XQuartz

brew install Caskroom/cask/xquartz
open -a Xquartz
/opt/X11/bin/xterm
Xterm Instance
ip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
export DISPLAY=$ip:0
/opt/X11/bin/xterm
sudo su -
ip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
export DISPLAY=$ip:0
/opt/X11/bin/xterm
No protocol specified
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
/opt/X11/bin/xterm: Xt error: Can't open display: %s

Allow connections from network clients

XQuartz Preferences
ip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
echo $ip
/opt/X11/bin/xhost + $ip

Run GUI Apps

docker run -i -e DISPLAY=$ip:0 jess/firefox
Firefox inside Docker
docker run -i -e DISPLAY=$ip:0 jess/spotify

Dimitris Kapanidis

Written by

Docker Captain, Google Developer Expert & Founder of Harbur Cloud Solutions (https://harbur.io)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade