Ssh – X11 forwarding from a docker container in remote server

dockersshx11

I want to ssh into my linux mint 18 server (running X11) and log into a docker container and have iPython matplotlib plots forwarded to the local client (also mint). All in the local network.

The closest question I found was: https://stackoverflow.com/questions/25281992/alternatives-to-ssh-x11-forwarding-for-docker-containers

Following this, I could get a plot GUI out from the docker to the local machine's display (e.i., the mint server) by -e DISPLAY=$DISPLAY option passed to the docker run command. I can also ssh with -X option to the server to get xeyes window to the client.

But if I ssh into the server with -X option and login to the container ran with -DISPLAY=localhost or client IP, I still cannot get a plot to the client machine.

I know I could use VNC to go around it. But, how can I do this with X11 forwarding properly?

Best Answer

You need to resolve these things for it to work:

  1. That the X application can find the X server
    • For SSH there needs to be a tunnel ("ssh -X" and "X11Forwarding yes" in /etc/ssh/sshd_config)
    • The address must be in $DISPLAY (using -e). You must replace "localhost" with the actual IP address of the Docker host seen from the Docker container.
  2. That the X application is authorised to talk to the X server
    • Propagate the xauth magic cookie into the Docker container
    • Open up any firewall ports from the Docker host to the Docker container for the X11 port
    • Make sure the SSH server is configured to accept X11 TCP connections on a remote IP.

See my question (and answer) here on StackOverflow for details of how it can be done: https://stackoverflow.com/questions/48235040/run-x11-application-in-a-docker-container-reliably-on-a-server-connected-via-ssh

Related Question