Launch a GUI application with Docker.

docker

Something that occasionally happens is there’s a version of software that is not compatible with your OS. Ok, just launch it with Docker! Well, not so fast, because it is Docker.

Here’s a case: I’ve running Ubuntu 16.04 LTS on my personal laptop, but I want to use Darktable’s newest version, 3.4, because there’s good documentation for that version. But, I can’t install it easily on Ubuntu 16.04, but I can on Ubuntu 18.04 Link.

This example has been adapted from my docker tutorials and Jessie Frazelle’s Docker containers on the Desktop post.

First, the Dockerfile. Darktable won’t let you run as root, so I had to create a user, user directory, permissions, etc.

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y \
	build-essential \
	cmake	\
	git \
	libgtk2.0-dev \
        curl\
	libavcodec-dev \
	libavformat-dev \
	libjpeg-dev \
	libpng-dev \
	libtiff-dev 

RUN apt-get install -y libcanberra-gtk-module 

RUN echo 'deb http://download.opensuse.org/repositories/graphics:/darktable/xUbuntu_18.04/ /' | tee /etc/apt/sources.list.d/graphics:darktable.list

RUN curl -fsSL https://download.opensuse.org/repositories/graphics:darktable/xUbuntu_18.04/Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/graphics_darktable.gpg > /dev/null

RUN apt-get update

RUN apt-get install -y darktable

#Make a user
ENV HOME /home/darktable-user
RUN useradd --create-home --home-dir $HOME darktable-user \
	&& chown -R darktable-user:darktable-user $HOME

WORKDIR $HOME

USER darktable-user

Build the docker image.

sudo docker build -t darktable-image .

Run it!

sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -v $PWD:/home/darktable-user darktable-image bash

Parts:

Graphics

This is the part I did not know how to do, and the Jessie Frazelle GUI section has more detail. You mount the X11 socket in the container, don’t have to the X11 forwarding business that I knew was a pain. This is done with a bind mount:

-v /tmp/.X11-unix:/tmp/.X11-unix

Pass the display:

-e DISPLAY=unix$DISPLAY 

Read-write

Here, I use another bind mount so that I can read raw files from my disk, and then write them as well.

-v $PWD:/home/darktable-user

This format is very specific. The arguments are: host file system path, colon (:), Docker image file system path. In this example, the host file system path is our current location ($PWD) (or whatever location you want to use as the bind directory on the host system), and the Docker image file system path is /home/darktable-user.

Running

After running

sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -v $PWD:/home/darktable-user darktable-image bash

You get a bash shell, then type darktable to launch the program. I like this approach because then I get to see all the error messages, etc.

Equivalently, you could launch darktable from the docker call,

sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -v $PWD:/home/darktable-user darktable-image darktable

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.