Does docker windows containers, with Docker Desktop for Windows, have default memory limit?
I have an application that was crashing when I run it in the container, but when I tried to specify --memory 2048mb
parameter to the docker run
command it seems to run fine. At least in the scenario where it was crashing before. This gives me impression that there is default memory limit, but I could not find it in the documentation. So my question is there memory limit and if it is where it is documented?
The maximum amount of memory the container can use. If you set this option, the minimum allowed value is 6m (6 megabytes). That is, you must set the value to at least 6 megabytes.
To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.
In the current Docker version, there is a default limitation on the Docker container storage of 10Gb.
The --memory parameter limits the container memory usage, and Docker will kill the container if the container tries to use more than the limited memory.
According to talks on Docker for windows Github issues (https://github.com/moby/moby/issues/31604), when Docker for Windows is run under Windows 10, it is actually using a Hyper-V isolation model (and process model is not accessible in Win 10 scenario).
And in that isolation type, your container is run inside a lightweight VM, which DOES have a default limit, and it is 1 Gb. So if you want to have more memory you should use -m param.
For me, on Windows 10 using Docker Desktop, I could not get the --memory=
and --cpus=
options to work. Here's what does work:
With WSL2, as documented here, you can create a .wlsconfig file in your user home directory, type from the PowerShell:
notepad "$env:USERPROFILE/.wslconfig"
And the contents of the file to limit memory are the following:
[wsl2]
memory=3GB # Limits VM memory in WSL 2 up to 3GB
In order to see if you are using WSL2 you can do so from the docker interface:
Surprise! Surprise!
I have 32Gb RAM on my host but I can see only 1Gb RAM given to Windows containers:
D:\>systeminfo | findstr "Memory"
Total Physical Memory: 1,023 MB
Available Physical Memory: 634 MB
Virtual Memory: Max Size: 1,023 MB
Virtual Memory: Available: 674 MB
Virtual Memory: In Use: 349 MB
D:\>wmic OS get FreePhysicalMemory /Value
FreePhysicalMemory=648340
D:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
1072742400
The same limit on images made from:
I think it's coming from the Hyper-V layer in --isolation=hyperv
mode, where a container is some sort of lightweight VM.
You can check isolation mode used for your existing container by docker inspect
command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With