Running docker GUI Apps in WLS2
Make sure you are using Windows 10 ( build 19044 or later ) or Windows 11
upgrade WSL to grabe the latest (WSLg)[https://github.com/microsoft/wslg] update.
# from an elevated command prompt or powershell.
wsl --update
# restart WSL
wsl --shutdown
Ceate Dockefile with bellow content:
FROM ubuntu
RUN apt-get update && apt-get -y install \
gedit \
&& apt-get clean && apt-get autoclean && rm -rf /var/lib/apt/lists/*
CMD ["gedit"]
build and Run .. Enjoy :)
docker build . -t guitest
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-e DISPLAY=:0 \
-e WAYLAND_DISPLAY=wayland-0 \
-e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir \
-e PULSE_SERVER/mnt/wslg/PulseServer \
guitest
for running Chome Browser:
FROM ubuntu
RUN apt-get update && apt-get -y install wget \
&& wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y ./google-chrome-stable_current_amd64.deb \
&& apt install --fix-broken -y \
&& apt-get clean && apt-get autoclean && rm -rf /var/lib/apt/lists/* \
&& rm google-chrome-stable_current_amd64.deb
CMD ["google-chrome","--no-sandbox"]
# build
docker build . -t chrome
# run
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-e DISPLAY=:0 \
-e WAYLAND_DISPLAY=wayland-0 \
-e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir \
-e PULSE_SERVER/mnt/wslg/PulseServer \
chrome