Docker X11 GUI setup
# Running Docker with X11 GUI Support on Ubuntu
This guide explains how to run a Docker container with GUI (X11) applications displayed on the Ubuntu host.
---
## 1. Allow X11 connections from Docker
```bash
xhost +local:docker
This command permits local Docker containers to access your X11 display.
2. Run the Docker container with X11 support
docker run -it \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
ubuntu:20.04
-
DISPLAY: passes host display to container. -
QT_X11_NO_MITSHM: avoids shared memory issues in some Qt apps. -
-v /tmp/.X11-unix: shares the X11 socket.
3. Inside the container: install GUI tools
apt update
apt install -y x11-apps
export QT_X11_NO_MITSHM=1
To test:
xeyes
A small GUI window should open on the host screen.
4. Revoke permissions (optional)
After exiting the container:
xhost -local:docker
Notes
-
This setup works for local Ubuntu hosts.
-
For remote setups (SSH, WSL, etc.), consider using X11 forwarding over SSH or VNC.
-
You can also build your own image with GUI tools pre-installed via Dockerfile.