Python Tkinter in Docker .TclError: couldn't connect to display
<p>I am new to python and am trying to build a small app. It needs to be a GUI app and I was wanting to containerise it with docker. I am getting the following error and can not find a solution</p>

<pre><code>No protocol specified
No protocol specified
Traceback (most recent call last):
  File "tkinker.py", line 7, in &lt;module&gt;
    tinker = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"
</code></pre>

<p>It starts locally but wont start in docker. My OS is Xubuntu.</p>

<p>I have created a sample app (below), see run-test.sh <a href="https://github.com/jeremysells/test/tree/master/docker-tkinter" rel="nofollow">https://github.com/jeremysells/test/tree/master/docker-tkinter</a></p>

<p>As <a href="https://hub.docker.com/r/dorakorpar/nsgui/" rel="nofollow">described here</a>, you would need an X11 graphic layer.<br>
But since you are already on an '(X)Ubuntu, setting the DISPLAY should be enough:</p>

<pre><code>export DISPLAY=127.0.0.1:0.0

docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix yourImage
</code></pre>

<p>Check also <a href="http://stackoverflow.com/a/25280523/6309">XAuthority</a>.</p>

python ubuntu docker tkinter xfce