X11 Forwarding with Docker on WSL¶
X11 forwarding allows graphical applications running inside a [[Docker]] container—typically on [[WSL]]—to display their GUI on the Windows host machine.^[600-developer__docker-run-command.md] This setup enables a seamless workflow for using Linux-based desktop tools within a Windows environment.
Prerequisites¶
To facilitate this connection, an X Server must be installed on the Windows host to listen for display requests.^[600-developer__docker-run-command.md] A common solution is VcXsrv (e.g., vcxsrv-64.1.20.14.0.installer.exe), available from sources like SourceForge.^[600-developer__docker-run-command.md]
WSL Configuration¶
The WSL environment requires the DISPLAY environment variable to be configured to point to the host's X Server.^[600-developer__docker-run-command.md] This can be automated by adding the export command to a shell configuration file such as ~/.bash_login:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
After saving the configuration, restart the WSL terminal to apply the changes.^[600-developer__docker-run-command.md]
Docker Execution¶
When launching the container, specific flags must be passed to the docker run command to enable graphical communication.^[600-developer__docker-run-command.md]
Key Flags¶
-e DISPLAY=$DISPLAY: Passes the display environment variable from the host (WSL) into the container, allowing the app to find the X Server.^[600-developer__docker-run-command.md]-v /tmp/.X11-unix:/tmp/.X11-unix: Mounts the X11 socket directory from the host into the container, enabling the communication channel.^[600-developer__docker-run-command.md]
Example¶
The following command demonstrates running a Tor Browser container with X11 forwarding enabled:
docker run -it \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
--name tor-browser \
jess/tor-browser
Related Concepts¶
- [[Docker]]
- [[WSL]]
- [[X11]]
Sources¶
^[600-developer__docker-run-command.md]