I'm trying to run a GUI application inside an Ubuntu Docker container on a Mac host machine.

My testing Dockerfile, tagged xterm, is

FROM ubuntu:xenial

RUN apt-get update && apt-get install -y xterm
RUN useradd -ms /bin/bash xterm
USER xterm
WORKDIR /home/xterm

Following this tutorial, I

  • allowed connections from network clients in XQuartz
  • started socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\", which printed E connect(5, LEN=4 AF=1 ":0", 4): No such file or directory.
  • Opened XQuartz
  • ran docker run -it --rm -e DISPLAY= --entrypoint /usr/bin/xterm xterm, where is the en0 IP address. This outputs /usr/bin/xterm: Xt error: Can't open display: and the error appears a second time in socat. No GUI is shown.

What does the socat error mean?

System details:

  • Docker Desktop, with Docker Engine 19.03.05
  • MacOS Mojave version 10.14.5
| improve this question | | | | |

It seems the XQuartz X Socket is named /tmp/.X11-unix/X0, at least that file gets created by XQuartz when XQuartz launches, but the DISPLAY variable contained ":0", so socat was forwarding to a non-existing socket.

When I use that file instead of ":0" in the socat command (socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:/tmp/.X11-unix/X0), I get no error anymore. Running the xterm container additionally prints No protocol specified before the Can't open display error.

That is resolved by authenticating, I ran xhost + which finally allowed running xterm, but that is insecure and it might be better to do it with xauth.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.