Low Orbit Flux Logo 2 F

Docker X11

It is possible to run X11 applications inside a Docker container. These instructions show you you can achieve this. This example shows how you can launch one of the most basic X11 programs available.

NOTE - You will probably want to run this as the same user that you are logged into the desktop. You will also want to make sure that you have permissions to manage Docker containers with that non-root user.

Create a new directory for your build:



mkdir test1
cd test1

Create a docker file like this:

vi Dockerfile
FROM ubuntu RUN apt-get update RUN groupadd -g 1000 user1 RUN useradd -d /home/user1 -s /bin/bash -m user1 -u 1000 -g 1000 USER user1 ENV HOME /home/user1 CMD /usr/bin/xeyes

Build the image:



docker build -t gui .

Run the container



docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -h $HOSTNAME -v $HOME/.Xauthority:/home/user1/.Xauthority gui

Firefox in Docker

This docker file should normally work but on newer versions of Ubuntu it will fail because Firefox is now distributed as a snap. It can probably be made to work with slight modifications.

vi Dockerfile
FROM ubuntu RUN apt-get update RUN apt-get install -y firefox RUN groupadd -g 1000 user1 RUN useradd -d /home/user1 -s /bin/bash -m user1 -u 1000 -g 1000 USER user1 ENV HOME /home/user1 CMD /usr/bin/firefox CMD /usr/bin/xeyes