You may need to deploy desktop applications with Docker but it does not normally provides a display server for running desktop applications. X11 Docker comes to your rescue. It allows running desktop applications and even entire desktop in Docker Linux containers. It runs an X display server on the host system and provides it to Docker containers. It additionally does some security set up which enhance container isolation and avoids X security leaks.
Features of x11 Docker
- Focus on security – X11docker runs additional X servers preventing X security leaks. It restricts container capabilities to bare minimum and ensures that container user is same as host user to avoid using root in the container.
- Less dependencies – It requires Docker installed beside X. There could be optional dependencies depending on the application you are running.
- Support various optional features including printer, sound, webcam and GPU.
- It is possible to remote access through ssh, VNC and html 5
- It is easy to use.
X11docker Supported Systems.
X11docker is fully supported on Linux. It also works on Windows OS but with set up and limitations. It does not run on MacOS.
Installing x11docker on Linux
x11docker simply needs bash, docker and an X server which is most probably already installed in your system. This is normally Xorg or Xwayland. You can install recommended base for your distribution, which are meant to give you advanced usage of x11docker.
Install x11docker dependencies on Debian|Ubuntu|Linux Mint:
sudo apt-get update sudo apt-get -y install xpra xserver-xephyr xinit xauth xclip x11-xserver-utils x11-utils
Install x11docker dependencies on Arch|manjaro Linux:
sudo pacman -S xpra xorg-server-xephyr xorg-xinit xorg-xauth xclip xorg-xhost xorg-xrandr xorg-xdpyinfo
Install x11docker dependencies on Fedora|CentOS:
sudo yum -y xpra xorg-x11-server-xephyr xorg-x11-xinit xorg-x11-xauth xclip xorg-x11-server-utils xorg-x11-utils
To install x11docker for the first time on your Linux system, run the following commands on your terminal.
# If using sudo curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update # If using root curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | bash -s -- --update
To update and remove x11docker, run the following commands:
x11docker --update: download and install latest release from github.
x11docker --update-master: download and install latest master version from github.
x11docker --remove: remove all files installed by x11docker. However, it does not remove ~/.local/share/x11docker where it stores persistent files of option –home or x11docker folders you might have created for yourself.
Running Desktop applications with x11docker
Once you have installed x11docker, you can available commands to be used with x11docker using –help. Some are as shown below:
$ x11docker --help x11docker: Run GUI applications and desktop environments in Docker containers. Usage: To run a Docker container on a new X server: x11docker IMAGE x11docker [OPTIONS] IMAGE [COMMAND] x11docker [OPTIONS] -- IMAGE [COMMAND [ARG1 ARG2 ...]] x11docker [OPTIONS] -- DOCKER_RUN_OPTIONS -- IMAGE [COMMAND [ARG1 ARG2 ...]] To run a host application on a new X server: x11docker [OPTIONS] --exe COMMAND x11docker [OPTIONS] --exe -- COMMAND [ARG1 ARG2 ...] To run only an empty new X server: x11docker [OPTIONS] --xonly Options: (short options do not accept arguments) --help Display this message and exit. -e, --exe Execute host application instead of docker command. --xonly Only create empty X server. Basic settings: (especially influencing automatical choice of X server) -d, --desktop Indicate desktop environment in image. -g, --gpu GPU access for hardware accelerated OpenGL rendering. Works best with open source drivers on host and in image. For closed source nvidia drivers regard terminal output. -w, --wm [=ARG] Provide a window manager to container applications. If available, image x11docker/openbox will be used. Otherwise x11docker looks for a host window manager. Possible ARG: host: Enforce autodetection of a host window manager. COMMAND: COMMAND can be a desired host window manager. IMAGE: IMAGE can be a local docker image with a WM. none: Run without a window manager. Same as --desktop. Shared host folders or Docker volumes: -m, --home [=ARG] Create a persistant HOME folder for data storage. Default: Uses ~/.local/share/x11docker/IMAGENAME. ARG can be another host folder or a Docker volume. (~/.local/share/x11docker has a softlink to ~/x11docker.) (Use --homebasedir to change this base storage folder.) --share ARG Share host file or folder ARG. Read-only with ARG:ro Device files in /dev can be shared, too. ARG can also be a Docker volume instead of a host folder. Host integration: -c, --clipboard Share clipboard. Graphical clips with --xpra only. -p, --pulseaudio [=MODE] Sound with pulseaudio. Needs 'pulseaudio' on host and in image. Optional arg MODE can be 'socket' or 'tcp'. --alsa [=CARDNAME] Sound with ALSA. You can define a desired sound card with CARDNAME. List of available sound cards: aplay -l -l, --lang [=LOCALE] Set language variable LANG=LOCALE in container. Without LOCALE host variable --lang=$LANG is used. If LOCALE is missing in image, x11docker generates it with 'localedef' in container (needs 'locales' package). LOCALE can be e.g. ru, en, de, zh_CN, cz, fr, fr_BE.
To enable remote access to X server, run the command below on your terminal.
$ xhost + Access control disabled, clients can connect from any host.
You can create dockerfile for running your desktop applications or download images from docker hub. Check example below:
Create a docker file to install Abiword. Use your preferred editor. I am using vim
$ vim Dockerfile
Add the following content
FROM ubuntu RUN apt-get update && apt-get -y install abiword CMD abiword
Create image from the dockerfile with build command
sudo docker build -t abiword .
Run Abiword container with X server
sudo docker run --rm -ti --net=host -e DISPLAY=:0 abiword
The application should open as below and you should able to perform the normal application operations.
The command below should install and run Eclipse application in Docker containers. It is going to pull the image since it is already locally available.
$ sudo docker run --rm -ti --net=host -e DISPLAY=:0 psharkey/eclipse
You should see it pulling eclipse image:
Eclipse application should open with X server and you can carry out normal eclipse operations.
This has been a guide on how to install and use x11docker on Linux to run GUI applications on Docker. This is quite useful especially when running developer applications and you need to run them in containers.
Best Docker Learning Courses:
- Docker Mastery: with Kubernetes +Swarm from a Docker Captain
- Docker for the Absolute Beginner – Hands On – DevOps
- Docker and Kubernetes: The Complete Guide
- Docker – SWARM – Hands-on – DevOps
- Docker Swarm Mastery: DevOps Style Cluster Orchestration
I hope the guide is helpful to you. Below are more interesting guides: