0

I get the error

_tkinter.TclError: couldn't connect to display ":0.0"

when I try to run my container. The following is my dockerfile.

#syntax=docker/dockerfile:1
FROM python:3.8
RUN pip install --upgrade pip
RUN useradd myuser
USER myuser
WORKDIR /home/myuser
COPY requirements.txt requirements.txt
ENV DISPLAY=:0.0
RUN pip install tk && \
pip install --no-cache-dir -r requirements.txt 
COPY . .
CMD ["python", "./python/ImageViewer.py"]

I have looked at other solutions and have set my DISPLAY variable to :1, :0, :$DISPLAY, and many more. I keep getting this error, I think it is because it is docker. I have also tried other solutions involving pip install other libraries and such. If anyone knows how to set the enviornment variable for DISPLAY for tkinter I would appreciate any tips. Thank you.

Rachel Kim
  • 85
  • 5
  • do you run XWindows in container? – furas Aug 05 '22 at 06:21
  • Because docker container doesn't have UI to show, so use [x11 vs xquartz](https://medium.com/@mreichelt/how-to-show-x11-windows-within-docker-on-mac-50759f4b65cb) to forward display from docker to host machine – AnhPC03 Aug 05 '22 at 08:12
  • Have you read through [Can you run GUI applications in a Linux Docker container?](https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-linux-docker-container) This is a tricky and non-portable setup, and you might find it easier to run this directly on the host. – David Maze Aug 05 '22 at 10:09

0 Answers0