title: Running a Qt GUI in a docker container
body: <p>So, I have a C++ GUI based on Qt5 which I want to run from inside a Docker container.</p>
  <p>When I try to start it with</p>
  <pre><code>docker run --rm -it my_image
  </code></pre>
  <p>this results in the error output</p>
  <pre><code>qt.qpa.xcb: could not connect to display localhost:10.0
  qt.qpa.plugin: Could not load the Qt platform plugin &quot;xcb&quot; in &quot;&quot; even though it was found.
  This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
  
  Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
  </code></pre>
  <p>So I searched for how to do this. I found <a href="https://stackoverflow.com/questions/35040020/gui-qt-application-in-a-docker-container">GUI Qt Application in a docker container</a>, and based on that called it with</p>
  <pre><code>QT_GRAPHICSSYSTEM=&quot;native&quot; docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix my_image
  </code></pre>
  <p>which resulted in the same error.</p>
  <p>Then I found <a href="https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-docker-container">Can you run GUI applications in a Docker container?</a>.<br />
  The accepted answer in there seems to be specific to certain applications such as Firefox?<br />
  Scrolling further down I got a solution that tells me to set <code>X11UseLocalhost no</code> in <code>sshd_config</code> and then call it like</p>
  <pre><code>docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority -e DISPLAY=$(echo $DISPLAY | sed &quot;s/^.*:/$(hostname -i):/&quot;) my_image
  </code></pre>
  <p>this produces a slight variation of the error above:</p>
  <pre><code>qt.qpa.xcb: could not connect to display 127.0.1.1:13.0
  qt.qpa.plugin: Could not load the Qt platform plugin &quot;xcb&quot; in &quot;&quot; even though it was found.
  This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
  
  Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
  </code></pre>
  <p>Following another answer, I added <code>ENV DISPLAY :0</code> to my Dockerfile and called it with</p>
  <pre><code>xhost +
  XSOCK=/tmp/.X11-unix/X0
  docker run -v $XSOCK:$XSOCK my_image
  </code></pre>
  <p>This time, the first line of my error was <code>qt.qpa.xcb: could not connect to display :0</code>.</p>
  <p>Then I tried another answer, added</p>
  <pre><code>RUN export uid=0 gid=0 &amp;&amp; \
      mkdir -p /home/developer &amp;&amp; \
      echo &quot;developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash&quot; &gt;&gt; /etc/passwd &amp;&amp; \
      echo &quot;developer:x:${uid}:&quot; &gt;&gt; /etc/group &amp;&amp; \
      mkdir /etc/sudoers.d/ &amp;&amp; \
      echo &quot;developer ALL=(ALL) NOPASSWD: ALL&quot; &gt; /etc/sudoers.d/developer &amp;&amp; \
      chmod 0440 /etc/sudoers.d/developer &amp;&amp; \
      chown ${uid}:${gid} -R /home/developer
  </code></pre>
  <p>to my Dockerfile and called <code>docker run -ti --rm    -e DISPLAY=$DISPLAY    -v /tmp/.X11-unix:/tmp/.X11-unix my_image</code>, again same error.</p>
  <p>I also tried several of the ways described in <a href="http://wiki.ros.org/docker/Tutorials/GUI" rel="noreferrer">http://wiki.ros.org/docker/Tutorials/GUI</a>, same error.</p>
  <hr />
  <p>Am I doing something wrong? Note that I'm working on a remote machine via SSH, with X11 forwarding turned on of course (and the application works just fine outside of Docker). Also note that what I write is a client-server-application, and the server part which needs no GUI elements but shares most of the source code works just fine from it's container.</p>
  <p>I hope for a solution that doesn't require me to change the system as the reason I use Docker in the first place is for users of my application to get it running without much hassle.</p>