From this article, it states that windows 11 natively supports running of X11 and wayland applications on wsl.
I tried to do the same through a docker container, settinng the environment variable DISPLAY="host.docker.internal:0.0"
, and running a gui application (like gedit
). But instead I got this error:
Unable to init server: Could not connect: Connection refused
Gtk-WARNING **: 17:05:50.416: cannot open display: host.docker.internal:0.0
2
Answers
I stumbled upon your question while attempting the same thing as you are and acctually got it to work with aid of this blog post on Microsoft. I use a minimal Dockerfile based on Ubuntu and installs
gedit
:Create the image the usual way, e.g.
docker build . -t guitest:1.0
On the WSL command line, start it like this:
I hope this is to good use for you as well.
This answer is heavily based on what chrillof has said. Thanks for the excellent start!
The critical things here for Docker Desktop users on Windows with WSL2 are that:
/tmp/.X11-unix
itself. This folder is actually found in the/mnt/host/wslg/.X11-unix
folder on the docker-desktop distribution which translates to/run/desktop/mnt/host/wslg/.X11-unix
when running containers.I found this GitHub issue where someone had to manually set environment variables which allowed me to connect the dots between what others experience directly on WSL2 and chrillof’s solution
Therefore, modifying chrillof’s solution using PowerShell from the host, it looks more like:
On my computer, it looks like
this (demo of WSLg X11)
To be clear, I have not checked if audio is functional or not, but this does allow you to avoid the installation of another X11 server if you already have WSL2 installed.