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).

Table of Contents

With SSH

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= debian
  • For the DISPLAY variable, run ip r and look for the IP of docker0 interface.
  • --rm removes the container when you exit from it.

Inside the container:

apt update
apt install -y openssh-server thunar nano
nano /etc/ssh/sshd_config
# /etc/ssh/sshd_config
# Modify these lines (uncomment if needed)
X11Forwarding yes
X11UseLocalhost no
mkdir -p /run/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, then change this line in /etc/ssh/sshd_config (uncomment if needed):

    PermitRootLogin yes

From the host:

ssh -X root@
  • Use container’s IP.
# Run thunar

Thunar with X11 forwarding

Without SSH

docker run -it --rm --net=host -v $HOME/.Xauthority:/root/.Xauthority:ro archlinux
  • This could work on containers in which the previous option does not work. Inside the container, run: export DISPLAY=:0.0.

Complete desktop enviroment

Check How to add a desktop enviroment via Docker to find some Docker images that include a desktop environment.