Sometimes, we need to forward the GUI from inside a Docker container. For example, you might want to run Chrome for CI/CD from within Docker but also view the interaction in headed mode rather than headless mode.
The process is quite simple: just bind /tmp/.X11-unix
and pass the DISPLAY
environment variable to the container. As a minimal example, I’ve created a Docker image that runs xeyes
, a simple application where eyes follow our cursor movement, to test if your X11 forwarding is working.
This should display xeyes
on your screen. Congratulations, you are now able to forward the GUI from inside a Docker container to your host screen.
If you encounter any problems, make sure that your local user, which is running Docker, has access to xhost
. You can verify this with the command:
If your user is not listed, you can whitelist it by running xhost +SI:localuser:[YOUR-USER]
.
If you’re interested in the image, you can find the source code on Github. It’s available in both Ubuntu and Alpine versions, with the latter being very small in size.