'Docker desktop eats all memory and crashes

Using Docker Desktop (19.03.13) with 6 containers in Windows 10. Having 16GB RAM.

In docker stats each container consumes 20-500 mb, all together cunsume ~1gb.

But in the Task Manager docker eats ~10gb and crashes from the lack of system memory.

How to check, what consumes so much memory in docker? And how to prevent this?



Solution 1:[1]

Try to create a .wslconfig file at the root of your User folder C:\Users\<my-user> to adjust how much memory & processors Docker will use.

This is the content of the .wslconfig file.

[wsl2]
memory=2GB   # Limits VM memory in WSL 2 up to 2GB
processors=2# Makes the WSL 2 VM use two virtual processors

Then, restart the computer. You will find the Vemm process will only take the amount of RAM you defined previously.

You can learn more here here

Solution 2:[2]

I guess you are using the new WSL 2 based engine, try switching docker engine back to Hyper-V by going opening docker settings -> general -> uncheck Use WSL 2 based Engine .

To explain:

I noticed it started happening to me since WSL 2 engine was introduced, i automatically switched to it since it's a new engine; Memory issues started arising since then.

Restarting/closing docker did not free the memory and i noticed in task Manager Vemm was the one eating all memory, so had to force close it (caused docker not to work).

Last thing i did was switching docker engine back to Hyper-V solved my high memory usage.

Solution 3:[3]

If you are using WSL2 put into the .wslconfig the middle of your ram. I don't know why but I had the same problem with 8GB RAM.

This is my .wslconfig

[wsl2]
memory=4GB # I have 8GB RAM
processors=2 

And the result was good because the consumption is good! In this moment I have running a Docker with 8 images:

The result was the following

Solution 4:[4]

As I know docker stats does not show RAM reservations. Try to put RAM limits using -m flag. There are some information how to control resources using docker: https://docs.docker.com/config/containers/resource_constraints/?spm=a2c41.12663380.0.0.59ed566dAqUZPu

Solution 5:[5]

Although this problem is already marked as SOLVED

There is still another reason for this, in recently updated versions.

You might enable too many resources for docker hyperkit.

Go to settings - resources - advanced check if you spared too much resource there. enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Alejandro Pérez
Solution 4 inser
Solution 5 cinqS