trying GUI apps with Docker

Published on 27 Feb 2015

I don’t really like installing Java. But I needed to install Java because Fiji depends on it. A few days ago I had read an article on using Docker to run GUI applications, written by Jessie Frazelle, and few months before that I bumped into an article talking about the same thing by Fabio Rehm.

I am using OS X. I downloaded Boot2Docker, installed it, and ran it. First thing first, create the Dockerfile.

# OpenJDK Java 6 JRE Dockerfile

# Pull base image.
FROM ubuntu:trusty

# Install Java, wget, and downloading+extracting Fiji
  apt-get update && \
  apt-get install -y wget && \
  apt-get install -y openjdk-6-jre && \
  wget && \
  tar -xvzf fiji-linux64.tar.gz

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64i

# Run Fiji

Command sudo docker build -t fiji . was issued, and the build went well. Tried running the fiji Docker image by issuing this command:

docker run -ti --rm \
       -e DISPLAY=$DISPLAY \
       -v /tmp/.X11-unix:/tmp/.X11-unix \

… and I was greeted with this error without sudo: "permission denied". And when I tried with sudo:

Are you trying to connect to a TLS-enabled daemon without TLS?

After googling that problem looks like a Boot2Docker-specific problem. But then, there’s another issue to take into account. The whole scheme of running GUI apps with Docker is not to forward x11 session through SSH or to use VNC, but to share the x11 socket between the host and the Docker container (the line -v /tmp/.X11-unix:/tmp/.X11-unix). The plot twist: by default, OS X has no x11 socket.

I cried.

update 9:25 AM, February 27 2015

After hours of hunkering down squashing the bugs, I have 1 bad news and 1 good news. I’ll proceed with the good news first: I failed. Fiji won’t run. Good news: I learned couple more things about running GUI apps with Docker container.

Lesson number 1: Use XQuartz

As I wrote before, the flag -v /tmp/.X11-unix:/tmp/.X11-unix can be used if and only if the host machine is running on Linux, so that the Docker container can utilize the host’s x11 socket, but such method can’t be done on OSX.

There is a way to do that: install XQuartz, thanks to this GitHub comment thread how to use -e DISPLAY flag on osx?

brew install socat
brew cask install xquartz
open -a XQuartz

# Run socat
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

Leave that terminal window open for socat to run. Open new terminal, spin up new Docker container from the image, e.g., fiji image.

docker run -e DISPLAY= fiji

I tested this with jess/geary image, and it worked. However, I still couldn’t get my fiji Docker image to run.

Lesson number 2: Boot2Docker TLS issue

Thanks to this thread on Stack Overflow, the solution is simple.

boot2docker poweroff # it is always a good idea to shut it down first
boot2docker start
$(boot2docker shellinit)

The issue should be fixed by now.

Lesson Number 3: Cheat Sheet

Well, uh, a cheat sheet for Docker.

Lesson Number 4: Java is a pain in the ass

I couldn’t get the fiji Docker image to run. Upon inspecting, I found it was almost impossible to run the Problems with permission error, command not found, et cetera. That’s it. I rest my case.