Eclipse inside a Docker Container
I remember having to use mock to test Fedora Eclipse from different releases, and the main reason I used this was to avoid having to create a VM. While there might be some cases today where I’d go through all that (depending on what I’d need to test), Docker images and containers offer an easy way to run Eclipse.
FROM fedora:22 RUN useradd me RUN dnf install -y eclipse-pde COPY ./init.sh / RUN chmod a+x init.sh CMD [ "/init.sh" ]
#! /bin/bash usermod -u $MY_UID -g $MY_GID me su me -c eclipse
From here, we simply build the image, giving the path to the folder containing the Dockerfile and the init.sh file.
docker build -t eclipse . ... docker run --rm --privileged -v /tmp/.X11-unix/:/tmp/.X11-unix/ -e DISPLAY=$DISPLAY -e MY_UID=$(id -u) -e MY_GID=$(id -g) eclipse
We ran the image in privileged mode, mounting the X11 socket, with the necessary environment variables. To keep from building up containers, we remove them upon exit.
The Eclipse instance should begin rendering within the host machine’s display. There have been a few cases where newer major versions of Eclipse had to be packaged as Copr repos because it wasn’t feasible to update the many required dependencies for a released version of Fedora. This approach seems like a nice way of getting the latest and greatest on an older host, or even testing an older release on a newer host.
If you’d like to use the graphics libraries from the container’s OS version, that can be done as well.
FROM fedora:22 RUN useradd me RUN dnf install -y mutter gnome-settings-daemon tigervnc-server-minimal eclipse-pde COPY ./init.sh / RUN chmod a+x init.sh CMD [ "/init.sh" ]
#! /bin/bash # Set d-bus machine-id if [ ! -e /etc/machine-id ]; then dbus-uuidgen > /etc/machine-id fi # Properly start d-bus mkdir -p /var/run/dbus dbus-daemon --system rm -f /tmp/.X*-lock Xvnc -SecurityTypes=none :3 & mutter -d :3 & su me -c eclipse
We build the image exactly as before and our image run command even becomes a little simpler. After the container is started, we connect to it on display :3 using a VNC client (eg. vncviewer from tigervnc), to see the running Eclipse instance.
$ docker build -t eclipse . ... $ docker run --rm -it --privileged -e DISPLAY=:3 eclipse ... $ vncviewer 172.17.0.2:3