title: X11 forwarding of a GUI app running in docker
body: <p>First off: I have read the answers to similar questions on SO, but none of them worked.</p>
  <p>IMPORTANT NOTE: The answer below is still valid, but maybe jump to the end for an alternative.</p>
  <p>The situation:</p>
  <ul>
  <li>App with GUI is running in a docker container (CentOS 7.1) under Arch Linux. (machine A)</li>
  <li>Machine A has a monitor connected to it.</li>
  <li>I want to access this GUI via X11 forwarding on my Arch Linux client machine. (machine B)</li>
  </ul>
  <p>What works:</p>
  <ul>
  <li>GUI works locally on machine A (with /tmp/.X11-unix being mounted in the Docker container).</li>
  <li>X11 forwarding of any app running outside of docker (X11 forwarding is set up and running properly for non-docker usage).</li>
  <li>I can even switch the user while remotely logged in, copy the <code>.Xauthority</code> file to the other user and X11 forwarding works as well.</li>
  </ul>
  <p>Some setup info:</p>
  <ul>
  <li>Docker networking is 'bridged'.</li>
  <li>Container can reach host (firewall is open).</li>
  <li><code>DISPLAY</code> variable is set in container (to host-ip-addr:10.0 because of TCP port 6010 where sshd is listening).</li>
  <li>Packets to X forward port (6010) are reaching the host from the container (<code>tcpdump</code> checked).</li>
  </ul>
  <p>What does not work:</p>
  <ul>
  <li>X11 forwarding of the Docker app</li>
  <li>Errors:</li>
  </ul>
  <p><code>X11 connection rejected because of wrong authentication.</code></p>
  <p><code>xterm: Xt error: Can't open display: host-ip-addr:10.0</code></p>
  <p>Things i tried:</p>
  <ul>
  <li>starting client ssh with <code>ssh -Y</code> option on machine B</li>
  <li>putting <code>&quot;X11ForwardTrusted yes&quot;</code> in ssh_config on machine B</li>
  <li><code>xhost +</code> (so allow any clients to connect) on machine B</li>
  <li>putting <code>Host *</code> in ssh_config on machine B</li>
  <li>putting <code>X11UseLocalhost no</code> in sshd_config on machine A (to allow non-localhost clients)</li>
  <li>Adding the X auth token in the container with <code>xauth add</code> from the login user on machine A</li>
  <li>Just copying over the <code>.Xauthority</code> file from a working user into the container</li>
  <li>Making shure <code>.Xauthority</code> file has correct permissions and owner</li>
  </ul>
  <p>How can i just disable all the X security stuff and get this working?</p>
  <p>Or even better: How can i get it working with security?</p>
  <p>Is there at least a way to enable extensive debugging to see where exactly the problem is?</p>
  <p>Alternative: The first answer below shows how to effectively resolve this issue. However: I would recommend you to look into a different approach all together, namely VNC. I personally switched to a tigerVNC setup that replaces the X11 forwarding and have not looked back. The performance is just leagues above what X11 forwarding delivered for me. There might be some instances where you cannot use VNC for whatever reason, but i would try it first.</p>
  <p>The general setup is now as follows:
  -VNC server runs on machine A on the host (not inside a docker container).
  -Now you just have to figure out how to get a GUI for inside a docker container (which is a much more trivial undertaking).
  -If the docker container was started NOT from the VNC environment, the <code>DISPLAY</code> variable maybe needs ajdusting.</p>