Running Qt Application using Docker on MacOS X

Muhammad Sahputra
2 min readNov 4, 2018

Nothing fancy. This subject has been discussed earlier by Nils De Moor on his blog, and also Sourabh Bajaj. This article intended only for my personal reminder.

I am not sure if it is possible without using socat, but in my case — similar to Nils, I have to use socat approach. As written by Nils, here’s how it works.

If you’re new to how X11 work and its correlation to Docker, you might want to start by reading this blog from Piergiorgio Niero.

The most important concept is,

  1. Containerised application bundled into docker working as X client, configured to send its DISPLAY towards X server.
  2. Socat creating 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 OS X host.
  3. Application start drawing its output, bridged by socat into X window on Mac OSX (XQuartz).

So the step would be,

  1. Make sure XQuartz running on MacOS X.
  2. Start socat
$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

3. Run docker container, for example:

$ IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
$ xhost + $IP; \
$ docker run -it \
-e DISPLAY=$IP:0 \
--volume="/Users/$USER:/home/$USER" \
--workdir=/home/$USER/development/matadewa/prototype/vehicle_counting \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
mst/matadewa:devel-base

4. And finally, run the Qt application from inside container.

Oh, one more thing, for the sake of my team who are usign Linux, you guys doesn’t need socat. Docker command below (sample) will serve the same purpose on Linux.

$ xhost +local:root;
$ docker run -it \
-e DISPLAY=unix$DISPLAY \
--workdir=$(pwd) \
--volume="/home/$USER:/home/$USER" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix" \
mst/matadewa:devel-base

That’s it!

--

--