Docker Community Forums

Share and learn in the Docker community.

Dockerfile and tkinter

I am new to the forum. I searched for the tkinter topic but I could not find any. Would members of the forum help me out? I created a docker image with my tkinter app. However, when I tried to run my image, I keep receiving this error message
Traceback (most recent call last):
File “./”, line 19, in
aarWin = tk.Tk()
File “/usr/local/lib/python3.8/tkinter/”, line 2261, in init = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

here is my Dockerfile
FROM python:3
CMD [ “python”, “./”]

I searched stackoverflow; it seems tkinter does not work in a container. Any suggestion is greatly appreciated!!


First, in order to run a python script in Docker is necessary to do it like this:

RUN python
Second, for your $DISPLAY error, you need first to specify a display to docker in order to use a GUI application. It usually can be done by adding

-v /tmp/.X11-unix:/tmp/.X11-unix:rw
to docker run.