Skip to content
Blog

How the WSL 2 Backend Works in Docker Desktop for Windows

Explore how Docker Desktop leverages the WSL 2 lightweight utility VM, vhdx dynamic virtual hard disks, Hyper-V architecture, and virtio-fs/9P mount performance on Windows.

Published on • November 17, 2026

AI Assistant

Before the Windows Subsystem for Linux version 2 (WSL 2), Docker Desktop on Windows relied on legacy Hyper-V Virtual Machines or VirtualBox. These legacy VMs required pre-allocating static CPU cores, fixed memory, and separate IP addresses.

With the introduction of WSL 2, Docker Desktop switched to a lightweight, deeply integrated utility VM architecture. This post explains how the WSL 2 backend works under the hood, how dynamic VHDX storage operates, and how to optimize cross-filesystem I/O performance.

Architecture: Lightweight Utility VM & Hyper-V Architecture

WSL 2 relies on the Hyper-V Architecture, but unlike traditional heavy virtual machines, WSL 2 uses a Lightweight Utility VM.

+-------------------------------------------------------------------------+
|                              WINDOWS HOST                               |
|   +-------------------+                     +-----------------------+   |
|   | Windows PowerShell|                     | Docker Desktop GUI    |   |
|   | / Command Prompt  |                     | (Control Panel)       |   |
|   +---------+---------+                     +-----------+-----------+   |
|             | (docker CLI)                              |               |
+-------------|-------------------------------------------|---------------+
              | Local AF_UNIX / Named Pipe                | RPC
+-------------v-------------------------------------------v---------------+
|                          WSL 2 UTILITY VM                               |
|   +-----------------------------+     +-----------------------------+   |
|   | docker-desktop-data (Distro)|     | docker-desktop (Distro)     |   |
|   | - Images, Containers, VHDX  |     | - dockerd, containerd, runc |   |
|   +-----------------------------+     +-----------------------------+   |
|                                                                         |
|   Linux Kernel (custom compiled with eBPF, cgroups v2, namespaces)      |
+-------------------------------------------------------------------------+
|                     Hyper-V Lightweight Hypervisor                      |
+-------------------------------------------------------------------------+

Dual WSL 2 Distributions

Docker Desktop provisions two custom background WSL 2 distributions (distros):

  1. docker-desktop: Contains the Docker daemon (dockerd), containerd, runc, and initialization binaries.
  2. docker-desktop-data: Holds storage state including container rootfs layers, volumes, and local images.

You can view these distributions using wsl.exe:

wsl --list --verbose

Output:

  NAME                   STATE           VERSION
* Ubuntu-24.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Storage Architecture: Dynamic VHDX Virtual Disks

The data stored in docker-desktop-data resides in a dynamically expanding Virtual Hard Disk (.vhdx file) located on your Windows host filesystem:

C:\Users\<User>\AppData\Local\Docker\wsl\data\ext4.vhdx

Dynamic Allocation & Shrinking Challenge

  • Expansion: As you pull images and build containers, Windows expands the .vhdx file automatically up to a default limit (usually 1 TB or host capacity).
  • Shrinking: Deleting containers or images with docker system prune frees space inside the ext4 filesystem inside the VHDX, but Windows does not automatically shrink the .vhdx file on the Windows host host disk.

To manually shrink and compact the VHDX file on Windows, execute Diskpart in PowerShell after stopping Docker:

# 1. Shutdown WSL
wsl --shutdown

# 2. Compact VHDX using diskpart
diskpart

Inside Diskpart:

select vdisk file="C:\Users\<User>\AppData\Local\Docker\wsl\data\ext4.vhdx"
compact vdisk
exit

Filesystem Performance: 9P Protocol vs Virtio-FS vs Native Linux

One of the most critical aspects of WSL 2 Docker performance is where your source code files reside when using bind mounts (-v / volumes).

1. Cross-OS Mounts (/mnt/c/ via 9P / Virtio-FS) — SLOW

Mounting code stored on the Windows filesystem (C:\Users\name\project) into a Linux container forces file I/O to traverse the cross-OS file translation bridge (historically 9P protocol, now accelerated with Virtio-FS).

# Slow: Source code on Windows NTFS filesystem mounted into Linux container
docker run -v C:\Projects\myapp:/app node:22 npm install

Performance Impact: File-heavy commands like npm install or cargo build across /mnt/c/ can be 5x to 10x slower due to filesystem translation overhead.

2. Native WSL 2 Mounts (\\wsl$\ or /home/user/) — FAST

Storing your project files directly inside the native WSL 2 Linux ext4 filesystem (e.g., inside your Ubuntu WSL distro home directory) delivers native Linux disk I/O performance.

# Fast: Executing inside Linux WSL 2 distro context
cd /home/username/projects/myapp
docker run -v $(pwd):/app node:22 npm install
+------------------------------------------------------------------------+
| Mount Path Location          | Filesystem Driver | I/O Performance     |
+------------------------------+-------------------+---------------------+
| C:\projects (Windows host)   | 9P / Virtio-FS    | Slow (Cross-OS)     |
| /home/user (WSL 2 Linux ext4)| Native ext4       | Extremely Fast (10x)|
+------------------------------------------------------------------------+

Memory Allocation & .wslconfig Tuning

By default, WSL 2 can consume up to 50% of your total host RAM (or 8GB+). To cap resource usage and prevent WSL 2 from starving Windows host applications, create %USERPROFILE%\.wslconfig:

[wsl2]
memory=8GB
processors=4
swap=2GB
guiApplications=false

Apply settings by restarting WSL:

wsl --shutdown

Takeaway: The WSL 2 backend provides native Linux container execution on Windows via a lightweight utility VM. To achieve maximum build and application performance, always store project source code inside the native WSL 2 Linux filesystem (/home/user/) rather than the Windows NTFS drive (C:\).

Sources