Reputation: 2619
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?
Upvotes: 43
Views: 67764
Reputation: 9961
You can check using the command sudo docker stats
and can see the memory allocation for the docker. As per my understanding, your docker is taking memory more than expected.
Solution:
It would be best if you allocated less memory, I updated my docker-compose.yaml
file and added below line to allocate and reserve the memory for docker as:
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 300M
After adding the above line your docker will take up to 512MB.
Here are sample docker-compose.yaml
file
version: '3' # Use version 3 or higher
services: # Use 'services' (plural) to define your services
backend:
container_name: track_easy_server_container
image: track_easy_server_image
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 300M
build:
context: .
target: production
dockerfile: ./Dockerfile
command: npm run start:prod
environment:
- APP_ENV=PROD
env_file: .env
ports:
- '3010:3010'
volumes:
- .:/user/src/app
- /usr/src/app/node_modules
restart: unless-stopped
Upvotes: 1
Reputation: 1
To solve the problem, you need to check if the file is named ".wslconfig.txt" and remove the ".txt" extension if it exists. Renaming the file to ".wslconfig" will resolve the issue.
Upvotes: 0
Reputation:
These are the settings I use on my old computer.
[wsl2]
memory=2GB # Limits VM memory in WSL 2 up to 2GB
processors=2# Makes the WSL 2 VM use two virtual processors
guiApplications=false #you won't use it with docker desktop
Upvotes: 3
Reputation: 1239
I have my docker taking less than 2% cpu now.
After updating .wslconfig to be:
[wsl2]
memory=8GB
swap=2000
processors=4
... and then restarting Docker, the CPU consumption was still over 80% and there were 5 Docker Desktop processes (each taking 17-18%) in Windows Task Manager. I reset Docket to Factory and still the CPU pegged at 80% or more.
I then deleted the .docker folder (in windows the path is %USERPROFILE%/.docker) as suggested by jmichalek-fp. I took care to do a Shift-DEL so as not to move it to the recylce bin because I remember in the past recycled items were still found by processes that hold a link to the file.
After Factory Reset, then increasing .wslconfig resources, then deleting .docker folder and then restarting Docker, it is now running only one Docker Desktop process, and, with a NodeJs app running in it, it is consuming between 0.5% and 2% CPU.
I found "delete .docker folder" in this github issue: https://github.com/docker/for-win/issues/12266
Upvotes: 6
Reputation: 1231
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
Upvotes: 54
Reputation: 231
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:
Upvotes: 12
Reputation: 1223
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.
Upvotes: 5
Reputation: 373
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.
Upvotes: 11
Reputation: 1210
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
Upvotes: 1
Reputation: 986
I am guessing on Windows there is something similar to what exists on MacOS.
Stats
You will get information regarding your CPU, RAM Usage, Disk Read & Write Memory & Network usage.
When I had memory issues, which I used to frequently, I would setup alias scripts that I could chain together to stop/kill/restart and do what ever setup I needed on the containers.
There is no preventing docker behaving the way it behaves unless you want to start contributing to and making pull requests. This isn't an uncommon issue. Docker is a free service, I recommend working around it's short comings.
Upvotes: -6