0

If there is a problem with how I set up this question, please tell me so that I can fix it for later.

I am attempting to figure out how to run a tkinter gui app within a docker container. I am using a 2020 macbook pro (intel) running MacOS Ventura 13.1 and docker version 4.15.0.

Error that I receive from docker:

Traceback (most recent call last):
  File "/app/tkinter_app.py", line 4, in <module>
    root_window = tk.Tk()
  File "/usr/local/lib/python3.8/tkinter/__init__.py", line 2270, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "10.100.113.144:0"

Error I receive from socat:

socat[74134] E UNIX-CLIENT:/private/tmp/com.apple.launchd.VW1pi4nBO9/org.xquartz:0: Connection refused

app/tkinter_app.py:


# Tkinter Window

root_window = tk.Tk()

# Window Settings

root_window.title('Application Title')
root_window.geometry('300x100')
root_window.configure(background = '#353535')

# Text

tk.Label(root_window, text='Hello World', fg='White', bg='#353535').pack()

# Exit Button

tk.Button(root_window, text='Exit', width=10, command=root_window.destroy).pack()

# Main loop

root_window.mainloop()

Dockerfile:

# Slim version of Python
FROM python:3.8.12-slim

# Download Package Information
RUN apt-get update -y

# Install Tkinter
RUN apt-get install tk -y

# Commands to run Tkinter application
CMD ["/app/tkinter_app.py"]
ENTRYPOINT ["python3"]

run.sh:


#!/bin/bash
docker build -t tkinter_in_docker .

docker run -u=$(id -u $USER):$(id -g $USER) -e DISPLAY=10.100.113.144:0 -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v $(pwd)/app:/app --rm tkinter_in_docker

Steps to reproduce:

  1. brew install socat
  2. brew install xquartz
  3. open -a Xquartz
  4. open xquartz settings window and enable connections from network clients
  5. chmod +x ./run.sh
  6. ./run.sh

File Structure:

app/

__ tkinter_app.py

Dockerfile

run.sh

0 Answers0