Essentially add this to the end of .bashrc
file in the Linux container.
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
This should have an associated firewall rule but to check it out and getting it to work under initial conditions, start X-windows allowing any connection, but this is very wrong so only do for the first test.
Currently the only need I have for X-windows with an Linux OS on WSL 2 is for running gtrace/0 with SWI-Prolog.
While it took a few hours and a few false starts and some attempts that partly worked, what I currently do is detailed in Remote development using Docker, WSL 2, Visual Studio Code and X-windows server
of this post.
EDIT
Don’t know if or how it is related but worth the note for future reference.
See: Ann: SWI-Prolog 8.3.21
specifically
:- initialization setenv('DISPLAY', ':0').