pythondockertkintersocatxquartz

Trying to use TkInter with Socat in Docker - Mac


Here's my steps..

Installing Socat and XQuartz

brew install socat
brew cask install xquartz

Opening XQuartz setting Socat Listener

open -a XQuartz
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

Running Docker container with DISPLAY environmental variable

docker run -e DISPLAY=192.168.0.13:0 tkinter sh

Here's the error I'm receiving.

// Container

_tkinter.TclError: couldn't connect to display "192.168.0.13:0"

// Socat

socat[37688] E connect(8, LEN=2 AF=1 "", 2): Invalid argument

Any other IP address gives me a similar error but doesn't show up in Socat so I can assume my IP is correct.

Any suggestion would be appreciated.


Solution

  • Are you trying to run a GUI app within docker? have you seen this method?

    after you open Xquartz you have to allow connections from network clients. I know on linux you have to share your .x11 volume and enable xhost and it looks like on a mac you have to do the same:

    ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
    xhost + $ip
    docker run -d --name displayContainer -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix <yourRepo>/<yourImage>