Wednesday, October 19, 2016

Running X11 Apps inside Docker on Remote Server

Background

Docker is fast-growing trend that I could no longer ignore, so I tried Docker running in a Linux server machine. Running server app is a breeze inside docker, but I need to run Pentaho Data Integration in the server, which uses X11 display. There is several references about forwarding X11 connection to a Docker container but none works for my setup, which has Quartz XServer running in  Mac OS X laptop and Docker service running in a remote Linux Server.

The usual way

The steps to run X Windowed Applications in Docker containers can be read from Running GUI Apps with Docker and Alternatives to SSH X11 Forwarding for Docker Containers, which essentially is as follows :
  1. Forwarding DISPLAY environment variable to the container
  2. Forwarding directory /tmp/.X11-unix to the container
I already tried such steps with no results, because I need to add another step before these two, that is forwarding X11 connection thru ssh connection to the server (not container). The step is as follows from an OS X laptop :

ssh -X username@servername.domain

Complications


We have DISPLAY set to something like localhost:10.0, and empty /tmp/.X11-unix directory. The reason is that forwarding thru ssh will result in TCP-based X11 service, and it is the opposite of unix socket based X11 service.



Inside the container, we are also unable to connect the localhost:10.0, because in the container the localhost would refer to the container's loopback interface, which is different from the host's loopback. For X11 display connections, the 10.0 means TCP port 6000+10, which as the result of X11 forwarding  only listens on 127.0.0.1 address.

Solutions

So we need to ensure the container able to connect to the forwarded X11 port. One solutions is to use socat :

nohup socat tcp-listen:6010,bind=172.17.0.1,reuseaddr,fork tcp:127.0.0.1:6010 &

Then the DISPLAY variable should be altered to point host IP in the docker network (172.17.0.1)


Unfortunately as you can see, there are authentication problems. I tried to copy the .Xauthority file from the host into the container, but it still failed. We could only understand why after getting it to work :

It seems that because different IP being used, the Xauthority file need a row with 172.17.0.1:10 as the key.

Having Xclock working, so we could also try something bigger like Pentaho's Spoon UI :

Additional notes

In order to get Pentaho Spoon UI working, I need to add gtk library as one layer in the Dockerfile :

USER root

RUN apt-get update && apt-get install -y libgtk2.0-0 xauth x11-apps

Caveat : for the formula editor to work in Spoon UI, we need to install firefox and libraries bridging firefox and swt, which is a topic for another post.

Conclusion

We have found out how to run X11-based apps from a Docker container with the X Server running in a laptop. What good does this for ? In some cases, we need to run a GUI-based app inside a Docker container, without installing vnc and x server inside the container. However we still have to provide X11 libraries inside the container.


1 comment:

GrayMatter Software Services said...

Thank you for writing such a good article on Pentaho Data Integration. Get some more details on Pentaho Data Integration and Pentaho Consulting