Justin's Blog

Running GUI Applications on Native Docker Containers for Mac

Justin Paul
Senior Principal Consultant
I use Docker for Mac a lot to do my work these days; especially with WebLogic. Usually I run scripts to install and configure the Oracle software, but I was curious if I could run GUIs from my containers. Actually I found it to be very easy to do. Here is how:
You will need to install 2.7.10 beta pre-release version of XQuartz or later. The current version has a bug which prevents XQuartz to use port 6000 on the host. This port is used by remote clients such as the Docker containers to display their GUIs. You can read about the bug here. You can dowload the latest version of XQuartz from here. Make sure you download a version equal to or greater than 2.7.10.
After installing XQuartz, start it and open XQuartz -> Preferences from the menu bar. Go to the last tab, Security, and enable both "Allow connections from network clients" and "Authenticate connections" checkboxes and restart XQuartz.
XQuartz Preferences -> Security Tab
Now your Mac will be listening on port 6000 for X11 connections. Record the IP Address of your Mac as you will need it in your containers.
$ ifconfig en0 | grep inet | awk '$1=="inet" {print $2}'

Add the IP Address of your Mac to the X11 allowed list.
$ xhost + being added to access control list
Start or connect to your Docker container. If you need to run the GUI as a different user, sudo to that user account at this time.
$ docker run -d --name=tempcontainer -t oraclelinux /bin/bash

$ docker exec -it tempcontainer /bin/bash

[root@2aea6bff8e08 /]# yum install -y -q firefox

[root@2aea6bff8e08 /]# groupadd -g 1000 oinstall && useradd -u 1000 -g 1000 oracle

[root@2aea6bff8e08 /]# su - oracle

[oracle@2aea6bff8e08 ~]$

Export the DISPLAY variable within your container. You will have to set it to ${MAC_HOST_IP_ADDRESS}:0.
[oracle@2aea6bff8e08 ~]$ export DISPLAY=

Start your GUI program and enjoy.
[oracle@2aea6bff8e08 ~]$ firefox
Note: Everytime you restart your computer, remember to add the IP Address of your Mac to the X11 allowed list.
$ xhost + being added to access control list

Join the discussion

Comments ( 2 )
  • Matteo Monday, October 17, 2016

    I was wondering if there is a way NOT to depend on the IP address of the Mac. I'm running Docker on a laptop and the IP address and the network interface change all the time. Is there another address (or maybe the possibility to create a dummy one) that allows to reliably identify the host computer?

  • Justin Paul Monday, October 17, 2016

    You can use either an IP or the hostname with the "xhost" command. Also, you ay be able to create a new network or assign a new static IP to your network interface. All we need is that X11 is listening on that IP and the Docker containers are able to reach it.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.