SSH GUI ?
X11 Forwarding with Docker and AlmaLinux
In this guide, we’ll walk through how to enable X11 forwarding with Docker and AlmaLinux so you can run graphical applications from within a Docker container on your host machine. We’ll use SSH to connect and display applications like gedit
on your local X server (e.g., XQuartz for macOS).
Prerequisites
Before starting, ensure the following:
- Docker is installed on your system.
- XQuartz is installed on your macOS (or X server on other platforms).
- Basic knowledge of Docker and SSH.
-
Install XQuartz (for macOS users).
-
Start Docker Container
Start an AlmaLinux container with port 22 mapped for SSH access:
docker run --rm -it -p 22:22 almalinux /bin/bash
This runs the AlmaLinux container and opens a bash session. The --rm
option ensures the container is removed when it stops, and -p 22:22
maps the SSH port.
- Install Required Packages Inside the Container
Inside the running AlmaLinux container, we need to install the necessary packages for SSH and a graphical editor (gedit
):
yum install -y openssh-server gedit
- Configure SSH for X11 Forwarding
To enable X11 forwarding, you need to configure SSH. Edit the SSH configuration file inside the container:
sed -i 's/#X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
This enables X11 forwarding and allows connections to be forwarded over the network.
Next, start the SSH service manually:
/usr/sbin/sshd
This forwards the display to your XQuartz server on macOS.
- Connect via SSH with X11 Forwarding
Now, from your host machine, you can connect to the container using SSH with X11 forwarding enabled. Open a terminal on your host (macOS) and run:
ssh -X root@localhost -p 22
Enter the root password (if configured earlier), and this will log you into the AlmaLinux container.
- Run a Graphical Application (like gedit)
Now that you’re logged into the container, you can run any graphical application that you installed. For example, run:
gedit
The gedit
window should appear on your macOS via XQuartz.
- Troubleshooting
-
If
gedit
or other apps don’t display, ensure that XQuartz is running, and that theDISPLAY
variable is set correctly. -
If you see an error related to
.Xauthority
, create the file manually inside the container:touch /root/.Xauthority