2016년 1월 23일 토요일

Enabling X11 in Docker containers

Docker containers generally don't come with Xorg installed because of the unnecessary bloat and the fact that most containers run applications that don't need X windows. However, it is possible for docker containers to use the host machine's X11!

Jessica Frazelle from Docker has lots of images on Dockerhub that support running GUI applications from a container. For testing docker + X11, I used the image jess/gparted.

In the container's dockerfile, which is on github, the command for launching the container is as follows:

docker run -v /tmp/.X11-unix:/tmp/.X11-unix \
  --device=/dev/sda:/dev/sda \
  -e DISPLAY=unix$DISPLAY gparted

For some reason the above invocation kept giving me the error:

Unable to find image 'gparted:latest' locally
Pulling repository docker.io/library/gparted
Error: image library/gparted:latest not found


I was able to launch the gparted container with the following commands:

[archjun@pinkS310 ~]$ docker run -ti --rm -e DISPLAY=$DISPLAY --device=/dev/sda:/dev/sda --device=/dev/sdb:/dev/sdb -v /tmp/.X11-unix:/tmp/.X11-unix jess/gparted:latest





Note that I have included the --rm flag so that the container will be deleted on exit instead of hanging around under /var/...

The order of the arguments is also different (which is probably unimportant). You will also notice that I specified two devices (/dev/sda and /dev/sdb) because my laptop has two drives. The crucial difference is that I explicitly specified the docker container name including the tag 'latest'.

For some reason, if I don't specify the tag, docker complains that it can't find the docker image.