WSL mounts your Windows file system under the /mnt directory.

compare WSL and docker

feature

Feature WSL Docker
Base Runs a real Linux kernel (in WSL2) on Windows via Hyper-V Uses Linux containers on a host OS
Isolation Less isolated — acts more like a Linux distro installed on Windows Fully isolated environments per container
File System Has access to the Windows file system (/mnt/c) Containers have isolated file systems
Aspect WSL Docker
Code Editing Use VS Code (Remote WSL), or edit directly in Linux paths Typically mount code from host or build images with code
Dependency Management Installed normally using apt/pip/etc. Installed inside Dockerfile or with docker exec
Portability Less portable — code tied to your WSL setup Highly portable — run same container on any platform
Build Environment Isolation Shared environment with your Linux setup Fully isolated per container, easy to create clean slates
Use Case Prefer WSL Prefer Docker
CI/CD pipelines ❌ Not used directly ✅ Widely used in DevOps pipelines
Performance-sensitive dev (I/O heavy) 🟡 WSL2 has performance overhead 🟡 Docker on Windows uses WSL2 backend (similar perf)
GUI

Starting from Windows 11, WSL2 includes WSLg, which natively supports Linux GUI apps.

On Windows 10 (without WSLg): You need to install a third-party X server, such as VcXsrv, Xming. Set the DISPLAY variable in WSL: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

Feature WSL (with WSLg) Docker on Windows
Native GUI Support ✅ Yes (Windows 11+) ❌ No native GUI
Qt/OpenCV/Matplotlib GUI ✅ Works out of the box ⚠️ Needs complex setup
X Server Required ❌ (if WSLg), ✅ (Win10) ✅ Always (e.g., VcXsrv or VNC workaround)
Performance 🟢 Smooth 🔴 Often slower, higher latency
Best for GUI App Development ✅ Recommended ❌ Not ideal

QA

01

code:

matplotlib.pyplot.show()

error:

Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

solution

  1. Use a GUI Backend with an X Server (Recommended for Visualizing) such as VcXsrv, X410, Xming.
  2. In WSL2 terminal, set the DISPLAY environment variable: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 . Or you can add it into ~/.bashrc or ~/.zshrc.
  3. (Optional) enable access to the X server: export LIBGL_ALWAYS_INDIRECT=1
  4. Install GUI backend dependencies if not already present: sudo apt install python3-tk python3-pyqt5
  5. run code. Matplotlib should use a GUI backend like TkAgg or Qt5Agg and open a window.

You can switch backend manually if you have GUI support.