I wrote an app in Python with a Tkinter GUI and I am trying to deploying it with Docker. I am having a hell of a time trying to figure out how to get it to work.
When I tried to run it locally, I got a "no display name and no $DISPLAY environment variable"
error.
I poked around found out I could fix that by adding this to my python script:
if os.environ.get('DISPLAY','') == '':
print('no display found. Using :0.0')
os.environ.__setitem__('DISPLAY', ':0.0')
Now I get _tkinter.TclError: couldn't connect to display ":0.0"
.
I tried adding -u=$(id -u $USER):$(id -g $USER) -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v $(pwd)/app:/app --rm <app name>
to my launch script (as suggested here) but this didn't fix anything.
I know this is a question that has been asked more than a few times, but it's an error that comes up a lot, and the problem seems to have a number of solutions across versions and platforms. Thanks.