Docker is commonly used for server-side and command-line apps. However, with the right setup, you can also run GUI-based applications inside containers. These containers can include GUI libraries and display tools, which enable apps to run in a secure and isolated environment. This approach simplifies developing, testing, and deploying GUI apps across different machines or OS environments. This guide will walk you through how to run GUI apps inside Docker containers with minimal setup.
Understanding Docker and Docker GUI Containers
Docker lets you package an application together with everything it needs, such as code, libraries, and settings, into a self‑contained unit called a container. These containers share the host system’s kernel, making them lightweight, fast to start, and efficient compared to full virtual machines.
GUI containers are Docker setups that include graphical applications, like Firefox, Gedit, or other desktop tools, allowing their windows to appear on your actual screen. Unlike standard containers, these require additional configuration to connect with the host’s display system, enabling proper rendering and interaction with GUI elements.
Why Run GUI Apps in Docker?
Here are the key reasons why running GUI apps in Docker can be beneficial:
- When you run a GUI app in Docker, everything it needs, like libraries and settings, is packed inside the container. This keeps your main system free from clutter or conflicts.
- Using Docker means your app will work the same on any machine. Whether you’re developing, testing, or sharing with others, the environment stays consistent.
- Containers make it simple to test a new app or debug something. You can run, pause, or remove them without affecting your host machine.
- Docker allows you to run Linux GUI applications on non-Linux systems. It does this by using display sharing tools like XQuartz or VcXsrv, so there’s no need for a virtual machine.
- Unlike traditional VMs, Docker containers use fewer system resources. They start faster and run more smoothly, even for GUI-based apps.
Run GUI Applications in Docker
To run GUI applications in Docker, you must first ensure that Docker is installed on your Linux system. You can check this by running the following command:
docker --version

If this command returns a version number, it means Docker is installed and working. If not, you’ll likely see a “command not found” error.
Once Docker is properly set up, you can move on to the next steps.
Activate Docker Service
Now, start the Docker service using the following command:
sudo systemctl start docker
To check if the Docker service is running properly, run:
sudo systemctl status docker
The output confirms that the Docker service is active and running without any issues:

Set Up Project Folder and Dockerfile
Let’s create a directory named “dockerGUI”, where we will store all the Docker-related files for running GUI apps:
mkdir dockerGUI
Now navigate to this directory to ensure that all subsequent files we create or modify will be kept in the dockerGUI folder:
cd dockerGUI
Create a new file named dockerGUIFile to define the Docker image configuration:
nano dockerGUIFile
Now, paste the following lines of code in the dockerGUIFile:
FROM jess/firefox
ENV DISPLAY=:0
CMD ["firefox"]
The above code tells Docker to use a prebuilt image of Firefox and sets the display environment so the GUI can appear on the host system. Moreover, it ensures Firefox launches automatically when the container runs.
Note: To try a different app, just change the image and the command in your Dockerfile. For example, to run Gedit, you can use the official Ubuntu image and install the app during the build like this:
FROM ubuntu
RUN apt-get update && apt-get install -y gedit
ENV DISPLAY=:0
CMD ["gedit"]
Build the Docker Image
Now that the Docker configuration is set up in the dockerGUIFile, let’s build the Docker image using the following command:
sudo docker build -t myfirefox:1 -f dockerGUIFile .
This command builds a Docker image from dockerGUIFile, names it myfirefox with tag 1, and uses the current directory as the context:

Launch Docker Container with GUI Support Enabled
Now, enable GUI support for Docker containers by running the following command:
xhost +local:docker
The output confirms that local clients (like Docker containers) running on my system are now allowed to connect to my X server:

Now, run the container using the following command to launch Firefox with GUI support on your host system:
docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix myfirefox:1
As a result, this command connects the container to your display, which allows Firefox to open on your screen just like a native app:

Note: Using the --rm
option makes Docker automatically delete the container after the app closes, keeping your system clean and preventing it from showing up in docker ps -s
.
Disconnect Docker from X Server
Once you’ve finished using the GUI application, it’s recommended to close the X server access for security reasons:
xhost -local:docker

Final Thoughts
Running GUI-based applications in Docker is a great way to extend what containers can do beyond the command line. With the right setup, you can launch desktop apps from a container as if they were installed on your system. It’s a simple yet powerful approach for testing, development, or exploring Linux tools in a clean environment. Start building your own GUI-ready containers and take full advantage of what Docker offers on your Linux desktop.