Running GUI’s with Docker on Mac OS X

Nils De Moor
Containerizers
Published in
4 min readJun 21, 2017

--

We are very familiar with running CLI processes in Docker containers with no Graphical UI at all. But did you know that you can just as well run applications with a graphical user interfaces, like Chrome, Firefox, Tor Browser, Gimp, etc… with Docker… on OS X!

This article serves as transcript to our hands-on demo and as a quick refresher on how to run these kind of applications on a Mac in 5 minutes or less. For a more in depth look on how to build and run Linux GUI apps on Mac I highly recommend the full from scratch rundown, by fellow Docker Captain Alex Ellis.

The first thing we need is socat, a unix tool that creates two bidirectional streams between two endpoints. Our end goal is to create a connection between the docker container that runs a graphical application and the X window system on our OS X host operating system. So lets begin by creating a bridge between a network socket with a TCP listener on port 6000 (the default port of the X window system) and the X window server on my OS X host, that we’ll install and run in the next step on a unix socket.

> brew install socat
> socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

Now we’ll tackle the X window system. To run this on Mac OS X we will need Xquartz which, according to the website, is a project that offers the X Window System on the OS X operating system. We can either install by downloading a dmg from the website. But since we are good developers we’ll do it from the command line through homebrew. (and yes, I do see the irony in saying that when advertising this post as being all about GUI’s…)

> brew install xquartz

One important thing to note is that after you have installed this is to log out and log back into OS X to get everything to work properly. Once that is done we can start Xquartz.

> open -a Xquartz

A white terminal window will pop up. Now open up the preferences from the top menu and go to the last tab ‘security’. There we need to make sure the “allow connections from network clients” is checked “on”.

And now we get down to business… running the actual graphical application within a Docker container!

docker container connecting to the X window system on the host OS X through socat

First we need the ip of the network interface of our host OS. Then we pass that on as the `DISPLAY` environment variable in the Docker container that runs the graphical interface.

> ifconfig en0
en0:

inet 192.168.0.235 netmask 0xffffff00 broadcast 192.168.199.255
> docker run -e DISPLAY=192.168.0.235:0 gns3/xeyes

All that trouble just to have 2 rolling eyes on your screen? Of course there is way more to explore. What about running chrome in a container? Apart from some extra permissions and a couple of warnings… easy as pie!

> docker run -e DISPLAY=192.168.0.235:0 --privileged jess/chrome

The possibilities are endless! So in just a couple of commands we’ve shown that docker shouldn’t be just used for the typical non-graphical applications. It can just be used as well for graphical apps. What use cases do you see valuable with this setup?

Check out our hands-on demo in the video below!

Running graphical applications on mac OS X live demo

--

--

Having fun with the tech stuff at @woorank. Alter ego's: entrepreneur, positivist, #DockerCaptain