Running GUI Software in Docker Containers on Red Hat Linux

Kaushik Denge
3 min readJul 27, 2023

Introduction:

Docker has become the go-to solution for containerization, allowing developers and operations teams to package applications and their dependencies into a single unit for easy deployment and scaling. While Docker is typically associated with server applications, it is also possible to run GUI (Graphical User Interface) software within a Docker container. In this blog, we will walk you through the steps to launch a Docker container in GUI mode and run GUI software on Red Hat Linux.

Prerequisites:

Before we begin, ensure you have the following:

1. Docker Installed: Ensure Docker is installed on your Red Hat Linux system. You can follow the official Docker documentation for installation instructions specific to your Red Hat Linux version.

2. X11 Forwarding Enabled: On your Red Hat Linux system, make sure X11 forwarding is enabled. This allows GUI applications in the container to display on the host.

Step 1: Install Required Packages

First, we need to install the necessary packages on the host machine to enable X11 forwarding. Open a terminal and run the following commands:


sudo yum update
sudo yum install xauth xorg-x11-server-utils xorg-x11-apps -y

Step 2: Configure X11 Forwarding

Next, configure the X11 server to allow connections from the Docker container. In the terminal, run the following command:


xhost +local:docker

This command allows the Docker container to access the X11 server on the host.

Step 3: Create a Dockerfile

Now, create a Dockerfile to build the container with the necessary configurations to run GUI software. In a directory of your choice, create a file named “Dockerfile” (without any file extension) and add the following content:


# Use Red Hat’s official minimal image as the base
FROM registry.access.redhat.com/ubi8/ubi-minimal

# Install necessary packages for GUI applications
RUN microdnf install -y \
xauth \
xorg-x11-server-Xorg \
xorg-x11-xauth \
xorg-x11-apps

# Set the display environment variable
ENV DISPLAY=host.docker.internal:0

# Install any additional dependencies required by your GUI software

# Set the working directory
WORKDIR /app

# Copy your GUI software to the container (adjust the path if needed)
COPY your-gui-software /app/

# Replace "your-gui-software" with the actual name or path to your GUI application.

# You may also need to add further configuration specific to your GUI software.

# Start the GUI application
CMD ["./your-gui-software"]

Step 4: Build the Docker Image

In the same directory where the Dockerfile is located, open a terminal and run the following command to build the Docker image:


docker build -t gui-container .

The `-t` flag tags the image with the name “gui-container” (you can choose any name you prefer).

Step 5: Run the GUI Container

Now it’s time to run the container with GUI support. Execute the following command:


docker run -it — rm — name gui-app \
-e DISPLAY=host.docker.internal:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
gui-container

In this command:
- `-e DISPLAY=host.docker.internal:0` sets the DISPLAY environment variable within the container to point to the host’s X11 server.
- `-v /tmp/.X11-unix:/tmp/.X11-unix` mounts the X11 Unix domain socket to the container, allowing GUI applications to communicate with the host’s X11 server.

Step 6: Enjoy the GUI Software

At this point, the GUI software should launch and display on your Red Hat Linux system. You can interact with it just like any other native application.

Conclusion:

Running GUI software inside Docker containers on Red Hat Linux is possible with the right configuration. By following the steps outlined in this blog, you can easily set up a containerized environment for your GUI applications. Remember to consider security implications and avoid running untrusted GUI software within Docker containers. Happy containerizing!

--

--