1

I wrote a small application in Python3 using Tkinter. I would like to containerize this application in order to reduce any installation and dependency hassle.

I wrote the following Dockerfile:

FROM python:3.6-buster

WORKDIR /home/python/app

COPY . .

RUN pip3 install -r requirements.txt

# Install my package
RUN python3 -m pip install --user --upgrade setuptools wheel
RUN python3 setup.py install

CMD [ "charts-app" ]

If I run the same commands outside Docker, everything works.

Inside Docker, I am able to build the image, but when I run it, the following message is displayed:

File "/usr/local/lib/python3.6/tkinter/__init__.py", line 2023, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

I understand that as the application is running inside the container, it has not directly access to a Graphical Interface. But, is there any way that I can "force" the container to use the host as its Graphical Interface?

Claudio Busatto
  • 721
  • 7
  • 17
  • Pick one from: [`[python][tkinter] $DISPLAY docker`](https://stackoverflow.com/search?q=is%3Aquestion+%5Bpython%5D%5Btkinter%5D+%24DISPLAY+docker) – stovfl Jan 03 '20 at 09:56
  • 1
    Opinion: packaging graphical applications in Docker just doesn't work well, you need to do a lot of fiddly setup to get it to run, you can only run the application as root, and you have to manually set up access to the host user's home directory. `pip install .` without Docker is vastly easier. – David Maze Jan 03 '20 at 10:58

0 Answers0