Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker containers are too slow on WSL 2 #4387

Closed
lucasctd opened this issue Aug 8, 2019 · 56 comments
Closed

Docker containers are too slow on WSL 2 #4387

lucasctd opened this issue Aug 8, 2019 · 56 comments

Comments

@lucasctd
Copy link

lucasctd commented Aug 8, 2019

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.

@Drakota
Copy link

Drakota commented Aug 8, 2019

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.

@lucasctd
Copy link
Author

lucasctd commented Aug 8, 2019

@Drakota Gonna give it a try then to see if it's the problem. I prefer to have the files on windows filesystem though cuz I like to hav e my code synced on OneDrive.

@lucasctd
Copy link
Author

lucasctd commented Aug 8, 2019

When I used Vagrant in the past the solution for this was enabling NFS feature on Windows. Have u tried this?

@Drakota
Copy link

Drakota commented Aug 9, 2019

Haven't used Vagrant with WSL or NFS yet unfortunately, let me know if moving your project's file fixed it.

@lucasctd
Copy link
Author

lucasctd commented Aug 9, 2019

I haven't tested it yet. It would take some time for me to move all the projects I have to my WSL home folder and I don't have time for that now. I have upgraded to build 18956, but it's still slow. So I went back to Docker for Windows.
I will keep an eye issues #4197 and this one too see if somebody has found a solution.
When the next build is released I will test it again too see if it got faster.
Thx.

@tuananh
Copy link

tuananh commented Aug 14, 2019

probably related to #4197

@therealkenc
Copy link
Collaborator

probably related to #4197

Almost certainly, since "transferring everything into my home directory" appears to mitigate. If your primary filesystem for Docker "work" (let's say a build) is on NTFS, then Windows Docker is a much better fit until filesystem perf improves.

@plokko
Copy link

plokko commented Mar 23, 2020

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

@LiamKarlMitchell
Copy link

Very slow how to fix?
Where is WSL home path?
Will try disabling Hyper V thanks @plokko I thought that was not used anymore but didn't think that it might slow down IO.

@xermus
Copy link

xermus commented Jun 5, 2020

Just to let you know: I have the same problem with WSL2 using WordPress containers. A pageview in my simple website takes 8s, while in WSL it takes less than a second. That's why I turned back to WSL1.

@lucasctd
Copy link
Author

lucasctd commented Jun 5, 2020

@xermus Are you using Windows Preview builds? If so, you will now be able to access your WSL home directory from Windows Explorer. So just move all your project files to your home directory and the slowness will be gone xD
You'll be able to work on your files with VS Code or PHPStorm normally.

@xermus
Copy link

xermus commented Jun 5, 2020

thanks @lucasctd - I tried it out, copied my project folder to the Desktop, set Docker to use WSL2 again, started the containers, but speed problem remained unfortunately. Reverting back to WSL1...

@lucasctd
Copy link
Author

lucasctd commented Jun 5, 2020

@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

@eried
Copy link

eried commented Jun 7, 2020

@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...

@dherran
Copy link

dherran commented Jun 22, 2020

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.

@eried
Copy link

eried commented Jun 22, 2020

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

@dominikbraun
Copy link

And here we go again, Docker Desktop...

@garbinmarcelo
Copy link

The solution at the moment is to return to Hyper-v, right? Because I'm making requests (I tested returns only one string) API that take a certain 6s.... =/

@lucasctd
Copy link
Author

lucasctd commented Jul 6, 2020

@garbinmarcelo Just place your code inside WSL's home directory. The slowness issue happens only when you try to access Windows FS from WSL.
In order to access your code from Windows Explorer (to open it on a IDE, text editor etc), just go to \\wsl$

@garbinmarcelo
Copy link

@garbinmarcelo Just place your code inside WSL's home directory. The slowness issue happens only when you try to access Windows FS from WSL.
In order to access your code from Windows Explorer (to open it on a IDE, text editor etc), just go to \\wsl$

Do I have to copy all the projects into wsl? Still, it is not a good solution, as I have several projects for example on the D: partition, in which case I would have to stop using this partition to use everything within the wsl path?

@lucasctd
Copy link
Author

lucasctd commented Jul 6, 2020

@garbinmarcelo Yep. Otherwise, you could use a NFS server on Windows, pointing it to your D partition and then install a NFS client on WSL to mount the partition there. I used to do it and worked pretty well, the only use issue I had was the lack of free NFS server softwares for Windows, I found two but they both didn't work, the only one that worked was a paid (and expensive [for me]) one xD

@garbinmarcelo
Copy link

@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 🍻

@eried
Copy link

eried commented Jul 6, 2020

Hyper-V worked for me. I have my github projects folder in another drive so that was the only option.

@garbinmarcelo
Copy link

Now I'm not getting back to Hyper-v... An error has occurred .. How can I go back, would you know?

This is the beginning of the error log:

Docker.Core.HttpBadResponseException:
Unhandled exception: job failed with message: Falha ao criar uma nova máquina virtual.

'DockerDesktopVM' não pôde reconhecer. (ID da máquina virtual F8017123-3BBF-497D-9C9E-2DE1D79B2457)

Falha ao acessar repositório de configuração: O sistema não pode encontrar o caminho especificado. (0x80070003).
   em Docker.Core.Logging.ClientExceptionInterceptor.<InterceptResponseAsync>d__0.MoveNext() na C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Logging\ClientExceptionInterceptor.cs:linha 17

@z3niths
Copy link

z3niths commented Sep 16, 2020

WSL2 also container based also still slow for me.

@LiamKarlMitchell
Copy link

Put your volumes/code etc into the Ubuntu or w/e WSL2 distro you are using.
It runs much faster and file polling works.

Create a network mapped drive for \wsl$\Ubuntu for example. (Replace with name of distro e.g. Ubuntu-20.04
You can't map into it like to the /home/ubuntu home directory sadly, but then you can goto that directory from "This PC" and copy over files.

Doing large operations with a git client or other tools from Windows can be slow though.

Run your docker-compose.yml or w/e up from the Ubuntu (Linux distro) WSL 2 and it goes much faster.

@Biswa96
Copy link

Biswa96 commented Sep 29, 2020

Using an actual GNU/Linux distribution installation in bare metal would be much faster and a lot easier that WSL itself. And that video would be just in 1 minute.

@mhelaiwa
Copy link

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

@SlyDeath
Copy link

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

@eried
Copy link

eried commented Sep 29, 2020

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

@mhelaiwa
Copy link

mhelaiwa commented Sep 29, 2020

@SlyDeath for me I need it because of MS Office, Adobe CC, and to work on old crappy .net projects.
So it’s better for linux to think about LSW Linux Sub-System for Windows 😅

@SlyDeath
Copy link

@enghelewa My condolences 😅

@laudeco
Copy link

laudeco commented Oct 15, 2020

@xermus Are you using Windows Preview builds? If so, you will now be able to access your WSL home directory from Windows Explorer. So just move all your project files to your home directory and the slowness will be gone xD
You'll be able to work on your files with VS Code or PHPStorm normally.

How do you execute your docker command then from your WSL or from your windows ?

@GF-Huang
Copy link

very slow, even if I run docker/getting-started, it stuck 10 minutes no responses.

image

@lucasctd
Copy link
Author

lucasctd commented Nov 4, 2020

@GF-Huang That's pretty weird, it runs really well here.

@microsoft microsoft deleted a comment from GF-Huang Nov 4, 2020
@codeninja
Copy link

Just want to bump this as it's Dec 8th with no resolution in sight. HTTP Requests against a Rails stack that executes in <1s on my macbook take 30+ seconds in WSL2 w/Windows.

@Biswa96
Copy link

Biswa96 commented Dec 9, 2020

tl;dr effect of virtualization.

@codeninja
Copy link

codeninja commented Dec 9, 2020 via email

@justyork
Copy link

Still nothing?

@eried
Copy link

eried commented Mar 31, 2021

Still nothing?

same slowness as 2 years ago

@l0gicgate
Copy link

At the risk of sounding like an absolute ungrateful twat, WSL 2 is a massive regression speed wise for docker containers when we were promised 20x the I/O performance. Where did it all go wrong?

@codeninja
Copy link

codeninja commented Jun 29, 2021 via email

@f-liva
Copy link

f-liva commented Jul 23, 2021

@codeninja how?

@noknokcody
Copy link

Can confirm, still a problem in Windows 11

@pepkolajk
Copy link

any solutions guys? wordpress site on docker so slow on windows 11

@noknokcody
Copy link

any solutions guys? wordpress site on docker so slow on windows 11

Best way I found to speed up performance is by using Hyper-V instead sadly.

@lucasctd
Copy link
Author

lucasctd commented Mar 4, 2022

@klodianpepkolaj have you tried docker for Windows with WSL2 integration? It should solve all your problems.

@noknokcody
Copy link

@klodianpepkolaj have you tried docker for Windows with WSL2 integration? It should solve all your problems.

Isn't that the exact problem this thread is detailing? That WSL2 runs terribly on windows when using Docker for Windows. I still haven't seen any notable improvement.

@lucasctd
Copy link
Author

lucasctd commented Mar 5, 2022

@noknokcody I don't think so. As some guys have already stated here, it will only be slow if you try to access the files under /mnt/c. Since Windows explorer, VS Code, PHPStorm etc are fully integrated with WSL filesystem, I don't see any reason for you to keep doing that.

Also, I suggested Docker for Windows cuz with that one you don't need to install docker and its dependencies manually on WSL and don't need to start it manually every time you restart WSL.

@noknokcody
Copy link

@noknokcody I don't think so. As some guys have already stated here, it will only be slow if you try to access the files under /mnt/c. Since Windows explorer, VS Code, PHPStorm etc are fully integrated with WSL filesystem, I don't see any reason for you to keep doing that.

Also, I suggested Docker for Windows cuz with that one you don't need to install docker and its dependencies manually on WSL and don't need to start it manually every time you restart WSL.

I currently run a few PHP dev environments through docker where I keep the source code on the host and mount a volume to the container to run my dev server. Currently, my workflow requires this source code to remain on the host. Are you suggesting that there is a way of avoiding slowdowns while adhering to this requirement?

@lucasctd
Copy link
Author

lucasctd commented Mar 6, 2022

@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

@noknokcody
Copy link

@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%.

@IslamChemirik
Copy link

any solutions guys? wordpress site on docker so slow on windows 11

Best way I found to speed up performance is by using Hyper-V instead sadly.

I was thinking about it because when i was using Docker with Hyper-v in about 3 years it wasn't that slow ( i had Windows running on HDD). I limited WSL2 Ram usage and CPU because it was abusive and it's still slower than it was with Hyper-v

@Rostish
Copy link

Rostish commented Apr 4, 2024

@noknokcody Hi!
Could you give an example for this tool?
I downloaded it, tried to mount from my wsl ubuntu console. But it doesnt work.
sudo mount -t nfs -o vers=2,nolock -v 192.168.1.100:/yasno /mnt/nfs mount.nfs: timeout set for Thu Apr 4 15:26:07 2024 mount.nfs: trying text-based options 'vers=2,nolock,addr=192.168.1.100' mount.nfs: prog 100003, trying vers=2, prot=6 mount.nfs: portmap query retrying: RPC: Timed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests