Docker Desktop eats RAM past WSL limit set in .wslconfig file

Finally, if your issue has not been addressed elsewhere, running:

  • :whale: :arrow_right: Settings :arrow_right: Diagnose & Feedback :arrow_right: Open Issues.

This forum is not an official product support or issue reporting channel.

This option does not exist…

I’m running Docker Desktop on Windows 10 Pro on 2 separate machines. 1 machine is only running a single item, the Portainer Extension. The other is running a number of containers.

I noticed when Docker Desktop is running for a time, usually more than a day, it starts to seriously start consuming RAM, to the point where it was maxing out my system’s RAM & causing memory errors. While this system was only running Portainer to manage the Portainer on the other system.

Looking for support I was directed to a post about WSL2 being the problem & IT taking a bunch of RAM, & a solution to set a limit to it’s usage with a .wslconfig file in C:\Users\#MYUSERNAME#\.wslconfig
My file is:

[ws12]
processors=1
memory=1GB
swapFile=F:\\TMP\\docker\\swap\\wsl-swap.vhdx
swap=16GB
pageReporting=true

But when I startup Docker Desktop the Vmmem usage immediately goes to 1,800MB but usually stops around 2,100 or 2,300. Which is much more than the 1GB limit that I set. Even with the file settings & multiple restarts after Docker Desktop has been running for a few days it will say in Task Manager that it’s using 6GBs but Resource Monitor will show Vmmem using as much as 18GBs. If I close Docker Desktop from the Task Tray Icon the RAM will go down to nothing. Other WSL2 entities will respect the 1GB limit, but Docker Desktop does not.

My other machine, which has been running Docker Desktop for a year or so hasn’t had such an extreme RAM problem, though I cannot say it had none as I did run into occasions where I couldn’t identify what was using it, but it never got to that point. Now I am having the same problem, I have set the .wslconfig allowing 5GBs of RAM & when closed I gain back as much as 12GBs of space, but it has yet to peg my RAM usage. It never had a very noticeable usage until after the update to Docker Desktop 4.11.1 (84025)

I have the same problem. I have .wslconfig limited to 6GB. I have a 32GB system. Without DD or WSL, it runs at about 12GB. When I start DD/WSL, system memory goes to 14 GB and then slowly grows to 31 GB !!! It grows over the weekend when I am not using the system. Selecting DD restart does not affect the memory graph. The only way I can recover the memory is to use powershell kill DD pid. System memory usage instatly goes down from 31 to 12 GB. I keep my DD updated and just updated again right now. I like developing with WSL and Docker Desktop, but this issue is a pain. I can remote desktop into my system in the morning and the lag is so great I can barely type until I once again.kill the DD pid. Using WSL-t docker-desktop abd WSL -shutdown does nothing. The other distributions (ubunto and docker-desktop-data) both terminate, but not docker-desktop. Looking a resource monitor shows the WSL VMEM with 3.1 GB.

Yeah, it’s gotten worse with the updates. For me right-clicking the Docker Desktop tray icon & Quiting Docker Desktop frees up most of it, but usually leaves around 2GB still in use, but as little as 1 & as much as the WSL limit I set. It does at times take a few minutes for it to free up. On rare occasions it does not free up at all until I shutdown WSL. that frees up everything, including what is still being used when I Quit every time, leaves my system using 5-8GB. The 5GB limit I currently have set seems to be respected by everything except Docker, but the Task Manager rarely shows it using much, it’s like Docker Desktop is taking RAM but telling the system it’s not. Within Docker Desktop it always says it’s using 3-5GB, never more
The system knows the RAM is gone, being used by something, but it’s chart of who’s using what doesn’t account for at times an extra 12GB that magically reappear when I Quit Docker Desktop or restart WSL. I feel Docker may even be taking the RAM then loosing it so the system can’t get it back, but Docker is not actually using it either.
For me personally it sometimes takes a few days before it inflates enough for it to cause a problem, then I just WSL --shutdown from the terminal (Powershell but command prompt should work as well) then reopen Ubuntu & Restart Docker Desktop.

I discovered something. It seems when I update images or build images in the CLI Docker uses RAM & doesn’t give it back or report it to the system. I was editing & rebuilding a container from Dockerfile & noticed I kept having abnormally high RAM usage very quickly. I quit WSL & restarted it, leaving it for a few hours. It my system had a steady 13GB used (It was using 7.9GB before I started Docker, my containers say they are only using just under 2GB of RAM, & I have 6GB set as a limit. I then rebuilt from the Dockerfile over & over & my system was using 21GBs. I repeated the process using the nocache option for building with the Dockerfile & it was the same result, though I stopped when it hit 19GB.

I don’t know why, but it seems that Docker uses RAM for this & obviously other tasks, but doesn’t give it back

Since it looks like we don’t have ideas why it happens and we can’t fix it, would you create an issue on GitHub? Please, check first if there is an open issue already.

Mention what you have discovered so far. It can help the developers to fix it sooner or report it to the developers of WSL if the bug is in WSL.

So I discovered my error. It seems to be working now now that I fixed it.

The .wslconf & wsl.conf files need to have Unix line endings. When I created mine I had actually done that, but I realized I made the mistake of editing it in Notepad which reverts it back to Windows Standard CR-LF instead of the Unix-style LF.
( Anyone unfamiliar with the Line Endings, a brief explanation: Back in the day Basic ended lines (Return) with a Carriage Return character while other systems would use the Line Fault character. This caused problems because if you opened a file in a program that used a different one from the file everything would be on a single line. Windows, for compatibility used both, so they could deal with Basic (What Mac used) files & the other standard without issue. The characters showed up as essentially a space that didn’t take up space so for text it was perfect. Now they still use the system & a lot of linux programs will see

[ws12]
processors=1
memory=1GB
swapFile=F:\\TMP\\docker\\swap\\wsl-swap.vhdx
swap=16GB
pageReporting=true

as

[ws12]␍
processors=1␍
memory=1GB␍
swapFile=F:\\TMP\\docker\\swap\\wsl-swap.vhdx␍
swap=16GB␍
pageReporting=true␍

so for “How Many Processors?” it thinks you put “1␍” processors & it says “I dunno what you mean”
it’s looking for the swap file in “F:\TMP\docker\swap\wsl-swap.vhdx␍” but there’s no file with that name, etc.

So for a solution there are a couple easy ways to make this work. 1st there’s a utility called Dos2Unix that you can use, I never use it so I can’t tell you much about it, but it’s a CLI tool that essentially just removes the from the end of each line. Or you can use an editor like Notepad++ which has a setting under View > Show Symbol > Show End of Line that will let you see what the file is using. There’s also a simple convert under Edit > EOL Conversion > Unix (LF). Then you just have to remember to edit it with Notepad++ not Notepad.

2 Likes

Just a small correction, although it doesn’t really matter. the character is Line Feed :slight_smile:

Thank you for sharing your solution. Line endings can cause a lot of trouble, but I would never have thought of it in this case.

Huh? Interesting. I mean I learned about it when I was a kid so maybe I remembered it wrong, but I distinctly remember thinking the name was confusing because “Fault” makes it sound like it’s failing or stopping not going to another line. If it was something else that didn’t make sense I’d be like sure, but that actually DOES make sense, which I guess makes it more likely, but I only remembered it because it didn’t…
Maybe I was taught misinformation, or maybe it’s one of those things that was modernly changed. Like cache, which in old computer texts in the glossary is said that the pronunciation is “Cash-A” but now it "<> ‘cash’ ". I saw that argument go on even after someone found a couple old books proving it.
Irregardless of that Line Feed makes much more sense.

Yeah, no problem, it really doesn’t make sense since it’s intended to be written within windows. In reality they should have it do a conversion upon startup before reading it, or just convert while making a copy of it to use internally as essentially that is what it’s doing anyway if the file is being read by Linux I guess. I personally created mine in Notepad++ which I have set to default to Unix-style, but when I edited it I did so it windows notepad & messed it up I guess. When I realized I figured there were probably plenty who had the same problem, & nowhere telling them why

I found a “nice” little tool in the Windows Store that makes this easier as it does the editing of the .wslconfig file for you…

Except it saves the file with CR LF Line Endings so it’s useless

So DON’T use the easyWSL tool because it is NOT your friend!