Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker on wsl2 very slow

After having read about the performance improvements when running Docker on wsl2, I have been waiting for the official release of Windows 10 that supports wsl2. I updated Windows and Docker and switched on the Docker flag to use wsl2 and was hoping for some performance boost for my Oracle Database running in a Docker container but unfortunately the change slowed down the container and my laptop dramatically. The performance of the container is about 10x slower and my laptop is pretty much stuck when starting the container. It seems as if the memory consumption would completely use up my 8GB and heavy memory swapping starts to take place. Is there anything I can do to improve the performance of Docker on wsl2 or at least to better understand what's wrong in my setup?

My environment:

  • Processor Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz, 2 Core(s)
  • Installed Physical Memory (RAM) 8.00 GB
  • Microsoft Windows 10 Pro Version 10.0.19041 Build 19041
  • Docker version 19.03.8, build afacb8b
like image 951
doberkofler Avatar asked Jun 02 '20 14:06

doberkofler


People also ask

Why is WSL2 so slow?

WSL2 uses the 9P protocol to access Windows drives, and it is currently known to be very slow when compared to: Native NTFS (obviously) The ext4 filesystem on the virtual disk used by WSL2. And even the performance of WSL1 with Windows drives.

Is Docker faster than WSL2?

Depending on your system's hardware performance, you likely found that WSL2 is the faster option.

Why is Docker running so slow?

When you experience slow Docker performance, check your CPU, memory usage, and available disk space. Consider upgrading your system if a component does not perform as expected. When dealing with a specific container that is performing worse than expected, it may be helpful to check container-specific metrics.

Can WSL2 run Docker?

By enabling the WSL 2 based engine, you can run both Linux and Windows containers in Docker Desktop on the same machine. (Docker Desktop is free for personal use and small businesses, for info on Pro, Team, or Business pricing, see the Docker site FAQs).


1 Answers

This comes from the "vmmem" which consumes as much resource as it can. To solve the problem just go to your user file for me in

C:\Users\userName

In this directory create a file named ".wslconfig" in which you will configure how many resources can consume WSL2:

[wsl2]  memory=900MB    #Limits VM memory in WSL 2 to 900MB  processors=1    #Makes the WSL 2 VM use one virtual processors 

Now close your docker and wait for "vmmem" to close in the task manager.

then You can restart docker and normally "vmmem" will not exceed the limit you have set (here 900MB) If don't work restart your computer.

I hope it helped you.

like image 148
Thezozolino L Avatar answered Sep 18 '22 14:09

Thezozolino L