Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Docker containers are very slow on Windows with WSL2

ErrorDocker on WSL2 very slow

Short answer

Docker on WSL2 is slow mostly because the project sits on the Windows drive (/mnt/c) and is bind-mounted into the container. Move the project into the Linux filesystem of your WSL distribution and mount it from there. If the whole machine slows down, cap the memory of the WSL 2 VM in .wslconfig.

  • Applies to Docker Desktop 4.x, WSL 2, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out where your project and the bind-mounted folder really live. A path starting with /mnt/c means the files are on the Windows side.

    pwd
    docker inspect --format '{{ range .Mounts }}{{ .Source }}{{ "\n" }}{{ end }}' my-container
  2. 2Match what you see, then jump to its fix

    1. 1The mount source starts with /mnt/c/... or the project is under C:\UsersThe bind-mounted source code lives on the Windows driveFix
    2. 2Your distribution is not listed under WSL Integration, so you work from Windows paths insteadWSL integration is off for the distribution you work inFix
    3. 3Windows itself becomes sluggish while containers runThe WSL 2 VM is using more memory, CPU or swap than the machine can spareFix

What does the error look like?

  • Docker on WSL2 very slow
  • npm install, builds or page loads take many times longer inside a container than in a Linux shell
  • File changes in a bind-mounted folder are not picked up by the watcher in the container

Cause 1 of 3

The bind-mounted source code lives on the Windows drive

1Check

Print the source of every mount of the slow container. Docker's WSL guidance warns against mounting paths such as /mnt/c/users because they come from Windows.

docker inspect --format '{{ range .Mounts }}{{ .Source }}{{ "\n" }}{{ end }}' my-container

2Fix

Copy the project into your WSL distribution's home folder, open a Linux shell and run Compose or docker run from there, so the bind mount source is a Linux path.

# in the WSL distribution, not in PowerShell
cp -r /mnt/c/Users/me/my-project ~/my-project
cd ~/my-project
docker run -v ~/my-project:/sources my-image

3Verify

The mount source no longer starts with /mnt/c, and the same build or install finishes faster.

docker inspect --format '{{ range .Mounts }}{{ .Source }}{{ "\n" }}{{ end }}' my-container

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

WSL integration is off for the distribution you work in

1Check

In Docker Desktop open Settings, Resources, WSL Integration and look at whether your distribution is switched on.

wsl -l -v

2Fix

Turn on WSL 2 integration for your distribution in Docker Desktop and keep your code inside that Linux distribution.

# Docker Desktop: Settings > Resources > WSL Integration > enable your distro
docker version

3Verify

docker version answers from inside the WSL shell.

docker version

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The WSL 2 VM is using more memory, CPU or swap than the machine can spare

1Check

Docker advises limiting memory, CPU and swap of the WSL 2 VM through the global WSL configuration file.

notepad $env:USERPROFILE\.wslconfig

2Fix

Add limits in the [wsl2] section of .wslconfig (memory and processors are documented keys, 50% of Windows memory is the default), then restart WSL.

[wsl2]
memory=6GB
processors=4

3Verify

After wsl --shutdown and a restart of Docker Desktop, the machine stays responsive under the same load.

wsl --shutdown

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Keep source code that you bind-mount in the Linux filesystem of the WSL distribution, never under /mnt/c.
  • Start docker and docker compose from a Linux shell, not from PowerShell, when the project lives in WSL.
  • Set memory and CPU limits for the WSL 2 VM once, in .wslconfig.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.