title: Inside a Docker Container: "Error: cannot open display: localhost:11.0"
body: <p>I am trying to use programs with a graphical interface in a docker container over ssh.</p>
  
  <p>Currently I am connected over ssh on an external machine where docker and the containers are running. On the host I can start programs like firefox which was displayed correctly.  The connection is established with:</p>
  
  <pre><code>ssh -Y root@host
  </code></pre>
  
  <p>When I try the same in a docker container, with the <code>firefox</code> image (see below):</p>
  
  <pre><code>docker run -it --privileged --rm \
      -e DISPLAY=$DISPLAY \
      -v /tmp/.X11-unix:/tmp/.X11-unix \
      -v /root/.Xauthority:/root/.Xauthority:rw \
      firefox
  </code></pre>
  
  <p>I just get:</p>
  
  <pre><code>Error: cannot open display: localhost:11.0
  </code></pre>
  
  <p>I already tried to set <code>xhost +</code> on the host, but it is still not working. 
  The host runs <code>Scientific Linux release 7.2</code> and the docker image is created with the
  <strong>Dockerfile from</strong> <a href="http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/" rel="noreferrer">http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/</a>:</p>
  
  <pre><code>FROM ubuntu:14.04
  
  RUN apt-get update &amp;&amp; apt-get install -y firefox
  
  # Replace 1000 with your user / group id
  RUN export uid=1000 gid=1000 &amp;&amp; \
      mkdir -p /home/developer &amp;&amp; \
      echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" &gt;&gt; /etc/passwd &amp;&amp; \
      echo "developer:x:${uid}:" &gt;&gt; /etc/group &amp;&amp; \
      echo "developer ALL=(ALL) NOPASSWD: ALL" &gt; /etc/sudoers.d/developer &amp;&amp; \
      chmod 0440 /etc/sudoers.d/developer &amp;&amp; \
      chown ${uid}:${gid} -R /home/developer
  
  USER developer
  ENV HOME /home/developer
  CMD /usr/bin/firefox
  </code></pre>