WSL: Docker containers are too slow on WSL 2

Your Windows build number:

Microsoft Windows [versão 10.0.18932.1000]

What you’re doing and what’s happening:

When making requests to nginx container on docker on wsl2, the server takes a lot of time to answer. A simple request that returns a plain ##text takes up to 4 seconds. After running sudo docker stats I got the following results:

image

flowmeapp_web_flowme_1 is the container that’s running nginx, as you can see it’s only consuming 3.4mb of memory and there are 14.6GB available.

I used to use the same containers on Docker for Windows and they worked fine so I don’t think it’s something with my docker-compose.yml file.

What’s wrong / what should be happening instead:

The request flow should be really faster than it is now.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 56

Most upvoted comments

I stumbled upon https://docs.microsoft.com/en-us/windows/wsl/compare-versions and discovered that WSL2 is actually slower than WSL1 if your project files are on the Windows file system. This was exactly my case as my project files were in C:\Users\etc…

So I decided to try 2 different things:

a) First I disabled the WSL2 integration in Docker so it would switch back to Hyper-V. Then I did docker-compose up -d in Powershell instead of the WSL console. The performance difference was huge, basic php pages that were taking about 8 seconds on WSL2 were now loading immediately with Hyper-V.

b) I also copied my project files into \wsl$\Ubuntu\home\ while having the Docker WSL2 integration enabled, then brought my images up with docker-compose from the WSL2 console. The performance gain was also huge and I didn’t notice any latency.

So it seems like it’s a file system performance issue. Sharing files between the Windows FS and Linux simply doesn’t work too well. If you want performance, you have to stick to one of the 2 options outlined above.

And here we go again, Docker Desktop…

@dherran I think this is the workaround for now, performance is terrible otherwise. I went back to Hyper-V for now, maybe until WSL3 😄

@enghelewa My condolences 😅

@enghelewa What is unique feature of windows if you already need Linux? Anyway, I think your opinion is correct.

Can confirm, still a problem in Windows 11

Disabling Hyper-v worked for me: i was desperate as i got less than 1MB/s for disk I/O; after i disabled Hyper-v now i get GB/s for disk I/O and about 40-50MB/s for mounted directories.

To disable Hyper-v run this command from an elevated Windows console (cmd or PowerShell): dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

No worries. Windows 11 is here and it’s sure to solve all our problems. /s

Thanks, Dallas

Professional leader of highly performant engineering teams since 1997 512.923.4426 | Github https://github.com/codeninja| Twitter https://twitter.com/dallaspool| Linkedin https://linkedin.com/in/dallaspool

Why is this closed? I mean @enghelewa solution is ok, but in terms of WSL2/WSL is quite crappy to need to find these workarounds

@lucasctd I also experience this problem. With Hyper-V I was compiling a project in about 5 minutes, now with WSL2 the operation takes about half an hour.

The volume is on the Windows FS tho…

@pdmwu Are you using Docker For Windows with that WSL integration feature? I am not using docker for Windows, I installed docker ce on WSL as I would do on a normal linux installation. To start docker just run sudo /etc/init.d/docker start

@Biswa96 For people who need windows for work it’s a decent solution

As the people here are saying. to go faster you need to move your code into WSL distro say into ~/projects/my-project after that you can access your code by cd into you project folder inside WSL and run these two commands:

  1. explorer.exe . this will share the folder with your windows 10 through a local network.
  2. code . if you have VS Code installed so this will allow you to edit your code by VS Code directly from windows.

See it in action in this video by Scott Hanselman @shanselman

@lucasctd Okay, so it’s almost (actually lol) better to use Linux hehehe… I’m seriously thinking about dualboot … I’ll try to go back to Hyper-v to see if there is any difference in speed… Valeuu brow 🍻

I’ve had this issue when my project files were in the Windows filesystem and being accessed from /mnt/c. I transfered everything inside my WSL’s home directory and that fixed it for me.

@noknokcody the only way I found to avoid slowness without having to put the files inside WSL’s filesystem was by using a NFS Server on Windows and then mounting the folders on WSL.

At the time, I used the following tool: https://www.hanewin.net/nfs-e.htm

Interesting solution, I might look into that a little more cheers! I still think this issue stands though, accessing files over /mnt/c is slow as heck, and volume mounting is a pretty significant docker feature to neglect. Microsoft is making big claims about the performance of WSL2 but still lag behind HyperV in this use case by at least 500%.