Run GUI Applications in Docker Containers With x11docker
As a developer, you might have a need to work with GUI containers. If that’s the case, you’ll quickly find that the traditional Docker runtime engine doesn’t provide for running GUI applications (unless they are of the web-based type). When you want to develop a containerized GUI application, what do you do?
Fortunately, there are plenty of third-party applications that make it fairly easy to launch GUI containers on a desktop. As you might expect, this does require a desktop environment (otherwise, you’d be developing on a more traditional server-based setup). One such application is called x11docker. As the name implies, this application works with the Linux X display server (which means you’ll need a Linux distribution to make it work).
Overview: What Is x11docker?
x11docker is a tool that allows developers to run GUI (Graphical User Interface) applications within Docker containers, providing features such as GPU hardware acceleration, sound support with PulseAudio or ALSA, clipboard sharing, and printer/webcam access.
Key Features of x11docker:
- Supports multiple container runtimes and backends.
- Includes Wayland support and language locale creation.
- Allows for persistent home folder and supports several init systems and DBus within containers.
Security Considerations:
x11docker avoids X server leaks by using multiple X servers, making it a secure option. This tool also creates a container user similar to the host user to avoid having to use root within the container.
Installation Process:
The article provides instructions on installing x11docker on a running instance of Ubuntu-based desktop operating system, including:
- Installing the Docker runtime engine.
- Adding necessary repositories and dependencies.
- Installing x11docker.
After installation, the article shows how to use x11docker by pulling the VLC media player image and running it within a container using the command x11docker –pulseaudio –share=$HOME/Videos jess/vlc.
Overall, x11docker allows developers to create custom containers for GUI applications, providing a convenient way to develop and deploy desktop software.
Getting Started With Docker and x11docker:
As a developer, you might have a need to work with GUI containers. If that’s the case, you’ll quickly find that the traditional Docker runtime engine doesn’t provide for running GUI applications (unless they are of the web-based type). When you want to develop a containerized GUI application, what do you do?
Fortunately, there are plenty of third-party applications that make it fairly easy to launch GUI containers on a desktop. As you might expect, this does require a desktop environment (otherwise, you’d be developing on a more traditional server-based setup). One such application is called x11docker. As the name implies, this application works with the Linux X display server (which means you’ll need a Linux distribution to make it work).
The x11docker application includes features like:
- GPU hardware acceleration
- Sound with PulseAudio or ALSA
- Clipboard sharing
- Printer and webcam access
- Persistent home folder
- Wayland support
- Language locale creation
- Several init systems and DBus within containers
- Supports several container runtimes and backends (including podman).
You might be asking yourself, “Isn’t X11 insecure?” Yes, it is. Fortunately, x11docker avoids X server leaks by using multiple X servers. So you can use the tool without worrying you’ll be exposing yourself, your system, or your containers to the typical X11 server weaknesses.
One thing to keep in mind is that x11docker creates an unprivileged container user. That user’s password is x11docker and restricts the capabilities of the container. Because of this, some applications might not behave as expected. For example, when trying to run the Tor Browser from within a container, it cannot access /dev/stdout, which means the container will not run. That’s not the case with all containers. I’ll demonstrate with the VLC media player, which does work as expected.
I want to show you how to install x11docker on a running instance of a Ubuntu-based desktop operating system. Of course, the first thing you must do is install the Docker runtime engine. For that, I’ll show you two different methods.
Ready? Let’s get this done.
What You’ll Need
As I’ve already mentioned, you’ll need a running instance of a Ubuntu-based Linux desktop distribution. You’ll also need a user with sudo privileges. That’s it.
Installing Docker Containers
First, we’ll go with the traditional method of installing the Docker runtime engine. The first thing to do is add the official Docker GPG to the system with the command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Next, we must add the Docker repository, so we can install the software. This is done with the command:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
With the repository added, we’ll then install a few dependencies using the command:
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
Update apt with:
sudo apt-get update
We can now install Docker with the command:
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
To be able to run Docker command without sudo (which can be a security risk), add your user to the docker group with the command:
sudo usermod -aG docker $USER
Log out and log back in so the changes take effect.
If you’d rather do this the quick way, you can install Docker with the following commands:
sudo apt-get install curl wget uidmap -y wget -qO- https://get.docker.com/ | sudo sh
To be able to run Docker rootless, issue the following command:
dockerd-rootless-setuptool.sh install
How To Install x11docker
Before we can install x11docker, we must install a few dependencies. This can be done with the command:
sudo apt-get install xpra xserver-xephyr xinit xauth xclip x11-xserver-utils x11-utils -y
Next, install x11docker with the command:
curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update
You can then update x11docker with the command:
sudo x11docker --update
How To Use x11docker
With x11docker installed, it’s time to test it out. Let’s test this with the VLC app container. First, pull the image with the command:
docker pull jess/vlc
Once the image has been pulled, run VLC (with the help of x11docker) with the command:
x11docker --pulseaudio --share=$HOME/Videos jess/vlc
You should see the VLC window open, ready to be used (Figure 1). It will be slightly slower than if the media was installed directly on your desktop but, otherwise, it should work as expected.
-

Figure 1: We’ve launched the VLC media player as a container.
Of course, that doesn’t help much if you’re a developer because you want to develop your own containers. You could always create the image you want to work with, tag it, push it to your repository of choice, pull it to your dev system with the docker pull command, and then deploy the container with x11docker.
And there you have it. You can now run GUI applications from within Docker containers, thanks to x11docker. Build on this by deploying your own, custom containers from your own images and see how it works.
FAQ
Q: What is the main difference between running GUI apps in traditional Linux environments versus using Docker containers?
A: Running GUI apps in traditional Linux environments typically requires installing and configuring specific packages, such as X11 or Wayland. In contrast, using Docker containers allows you to run GUI apps without modifying your host system, making it easier to create and manage isolated environments.
Q: Do I need a separate operating system for running GUI apps with Docker?
A: No, you don’t need a separate operating system for running GUI apps with Docker. You can use the same Linux distribution as your host OS and install necessary packages using Docker containers.
Q: How do I run a GUI app in a Docker container?
A: To run a GUI app in a Docker container, follow these general steps:
- Pull the desired image (e.g., docker pull jess/vlc for VLC media player).
- Run the image using x11docker or another GUI-specific runtime tool.
- Configure any necessary settings, such as shared directories or display output.
Q: What are some common issues when running GUI apps in Docker containers?
A: Some common issues include:
- Inability to connect to external resources (e.g., USB devices).
- Lack of proper input/output redirection.
- Difficulty with keyboard and mouse interactions.
- Issues with display rendering or scaling.
Q: How do I troubleshoot problems with running GUI apps in Docker containers?
A: Troubleshooting typically involves:
- Checking the container logs for error messages.
- Verifying that necessary packages are installed and configured correctly.
- Ensuring that shared directories are properly set up.
- Using debugging tools to inspect the application’s behavior.
Q: Can I use x11docker with other Docker runtimes?
A: No, x11docker is specific to running GUI apps using X11. Other Docker runtimes (e.g., –rm –net=none) may not provide the necessary environment for proper GUI app execution.
Q: Are there any performance implications when running GUI apps in Docker containers?
A: Running GUI apps in Docker containers can introduce some overhead due to:
- Increased process isolation.
- Higher memory requirements (for shared directories and X11 sessions).
- Potential network latency.
- However, the impact on performance is typically minimal compared to running native applications.
Q: Can I use x11docker with other Linux desktop environments?
A: Yes, x11docker can be used with various Linux desktop environments, including:
- GNOME
- KDE
- XFCE
- LXDE
Just make sure to configure the container properly for your chosen desktop environment.