Running GUI applications with Docker in OSX

A quick guide on how to run docker containers requiring a GUI with Mac and XQuartz. First, you’ll need to download and install XQuartz. Run it.
Now, start socat to expose local xquartz socket on a TCP port:

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

Pass the display to container :

docker run -e DISPLAY=192.168.99.1:0 pygame xclock

I’m assuming that 192.168.99.1 is your vboxnet IP address and that «pygame» is the name of the docker image that contains your GUI application (in this case, my container’s name is pygame and the GUI is xclock)

For security purposes, you can use socat option range=/32 to filter the IP address (allowing only your primary IP to connect). Check also your XQuartz Preferences / Security tab:

Magic!

You can also launch a bash shell first and from there, run your GUI apps.

Sources:
[1] https://github.com/moby/moby/issues/8710#issuecomment-71113263
[2] http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/
[3] https://github.com/CustardCat/pygame-docker