I\'m attempting to get XQuartz to work on OSX so I can do X11 forwarding via Docker. I\'m following the instructions here. I believe my question may be answer
Went through all the pain to get the simplest version possible that does not depend on checking port, ip, etc... Here it is.
XQuartz 2.7.11 (xorg-server 1.18.4)
docker version 18.06.1-ce
Make sure to install XQuartz
$ brew install socat
$ brew cask reinstall xquartz
On a new terminal, verify if there's anything running on port 6000
$ lsof -i TCP:6000
$
If there is anything, just kill the process
Open a socket on that port and keep the terminal open
$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
In a new terminal, verify if it is opened
$ lsof -i TCP:6000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 29298 mdesales 5u IPv4 0xe21e43ca9d99bf1d 0t0 TCP *:6000 (LISTEN)
$ cat Dockerfile.eyes
FROM centos
RUN yum install -y xeyes
CMD ["/usr/bin/xeyes"]
$ docker build -t eyes -f Dockerfile.eyes .
The magic happens using the variables from Docker. Just using the -e DISPLAY=docker.for.mac.host.internal:0
did the trick, as it it will point to the internal IP address and provide that to the docker image. The port forward will do its magic.
$ docker run -e DISPLAY=docker.for.mac.host.internal:0 eyes
I noticed that at this point XQuartz is opened on it own to the same port
$ lsof -i TCP:6000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 29298 mdesales 5u IPv4 0xe21e43ca9d99bf1d 0t0 TCP *:6000 (LISTEN)
X11.bin 29462 mdesales 8u IPv6 0xe21e43ca7cdb1135 0t0 TCP *:6000 (LISTEN)
$ docker run -e DISPLAY=docker.for.mac.host.internal:0 jess/tor-browser
$ docker run -e DISPLAY=docker.for.mac.host.internal:0 batmat/docker-eclipse