Skip to content

WSL DISPLAY configuration for X11

The DISPLAY environment variable is the primary mechanism used by X11 clients to locate the server. In WSL 1 and WSL 2, this variable typically does not exist by default and must be configured manually.^[600-developer-docker-run-command.md]

Configuration for WSL 1/2

To enable graphical applications, the DISPLAY variable must be set to the host machine's IP address followed by the display number (usually 0).^[600-developer-docker-run-command.md]

A persistent configuration can be added to the shell startup file (e.g., ~/.bash_login) by extracting the nameserver IP from the /etc/resolv.conf file^[600-developer-docker-run-command.md]:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

After saving this configuration, restart the WSL session to apply the changes^[600-developer-docker-run-command.md].

X Server Requirement

Configuring the DISPLAY variable alone is insufficient; an X Server (such as VcXsrv) must be installed and running on the Windows host to handle the rendering^[600-developer-docker-run-command.md]. Once the X Server is active and DISPLAY is set, graphical tools like gedit or xeyes can be launched from the WSL terminal^[600-developer-docker-run-command.md].

Docker Integration

When running Docker containers that require a GUI, the DISPLAY variable from the WSL host must be passed into the container^[600-developer-docker-run-command.md].

Additionally, the X11 socket must be mounted as a volume to allow communication between the container and the host's X Server^[600-developer-docker-run-command.md]. The standard command syntax is^[600-developer-docker-run-command.md]:

docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    <image-name>

Sources

  • 600-developer-docker-run-command.md
  • [[Docker]]
  • [[X11]]