Running desktop apps on Docker containers: X11 forwarding
If you want to do X11 forwarding from your container to your host, you can type these simple commands (these methods work on a local machine, if you are connecting to a remote machine with SSH, it won’t work).
Podman users: you can run these commands with
podman, just replace
Table of Contents
In this method, we are going to install an SSH server on the container. Then, we are going to forward the Thunar File Manager.
docker run -it --rm -e DISPLAY=172.17.0.1:0.0 debian
- For the DISPLAY variable, run
ip rand look for the IP of
--rmremoves the container when you exit from it.
Inside the container:
- Install SSH server, a text editor and the graphical application
apt update apt install -y openssh-server thunar nano
/etc/ssh/sshd_configto enable X11 forwarding:
# /etc/ssh/sshd_config # Modify these lines (uncomment if needed) X11Forwarding yes X11UseLocalhost no
sshd, SSH daemon:
mkdir -p /run/sshd /usr/sbin/sshd
You can add a user if you don’t want to ssh to the container with the root user:
useradd -m ricardo passwd ricardo
If you want to use root, first add a password to the root (
passwd root), then change this line in
/etc/ssh/sshd_config (uncomment if needed):
From the host:
- Connect to the container (using container IP)
ssh -X firstname.lastname@example.org
- Run the graphical application:
docker run -it --rm --net=host -v $HOME/.Xauthority:/root/.Xauthority:ro debian
Inside the container (I’m going to install
xterm, a terminal emulator):
export DISPLAY=:0.0 apt update apt install xterm xterm
Complete desktop environment
Check How to add a desktop environment via Docker to find some Docker images that include a desktop environment.
If you have any suggestion, feel free to contact me via social media or email.