Docker containers are very slow on Windows with WSL2
Docker on WSL2 very slowShort 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.
Fix it fast
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-container2Match what you see, then jump to its fix
- 1
The mount source starts with /mnt/c/... or the project is under C:\UsersThe bind-mounted source code lives on the Windows driveFix - 2
Your distribution is not listed under WSL Integration, so you work from Windows paths insteadWSL integration is off for the distribution you work inFix - 3
Windows itself becomes sluggish while containers runThe WSL 2 VM is using more memory, CPU or swap than the machine can spareFix
- 1
What does the error look like?
Docker on WSL2 very slownpm install, builds or page loads take many times longer inside a container than in a Linux shellFile 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-container2Fix
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-image3Verify
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-containerConfirmed by docs.docker.com
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 -v2Fix
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 version3Verify
docker version answers from inside the WSL shell.
docker versionConfirmed by docs.docker.com
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\.wslconfig2Fix
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=43Verify
After wsl --shutdown and a restart of Docker Desktop, the machine stays responsive under the same load.
wsl --shutdownConfirmed by learn.microsoft.com
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
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
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