Python Tkinter in Docker .TclError: couldn't connect to display Python Tkinter in Docker .TclError: couldn't connect to display tkinter tkinter

Python Tkinter in Docker .TclError: couldn't connect to display


As described here, you would need an X11 graphic layer.
But since you are already on an '(X)Ubuntu, setting the DISPLAY should be enough:

export DISPLAY=127.0.0.1:0.0docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix yourImage

Check also XAuthority.


You'll have to set DISPLAY in the container. You can add it as an argument to the docker run command like this:

docker run -ti -e DISPLAY=$DISPLAY blah-image blah-command

DISPLAY should be set in the Xubuntu shell you are running the command from.


Type xhost + in your terminal. Then

docker run --rm \    --network=host --privileged \    -v /dev:/dev \    -e DISPLAY=$DISPLAY \    -v /tmp/.X11-unix:/tmp/.X11-unix \    -v $HOME/.Xauthority:/root/.Xauthority \    -it yourimage

worked for me. xhost + disables access control. After which a client can connect from any host.