Limiting Docker RAM Usage on Windows
Jenuel Oras Ganawed

Jenuel Oras Ganawed @jenueldev

About: Hi! I am a Software Developer

Location:
Ambabag, Guinaoang, Mankayan, Benguet
Joined:
Dec 23, 2019

Limiting Docker RAM Usage on Windows

Publish Date: Feb 21
5 0

If you're running Docker on Windows, managing its RAM usage depends on whether it's using Hyper-V or WSL 2. When Docker runs with Hyper-V, you can easily adjust resource limits through the settings in the desktop app. However, if you're using WSL 2 (which is the recommended approach), the RAM usage settings won't be available in the GUI.

How to Limit RAM Usage for Docker in WSL 2

By default, Docker in WSL 2 will consume up to half of your system's memory. If you have a high amount of RAM (e.g., 32GB or 64GB), this can be excessive. To manually set a RAM limit, follow these steps:

1. Navigate to Your User Directory

Run the following command in PowerShell or Command Prompt to switch to your home directory:

cd ~
Enter fullscreen mode Exit fullscreen mode

2. Edit or Create the .wslconfig File

In your home directory, look for a file named .wslconfig. If it doesn’t exist, create one. Then, add the following lines:

[wsl2]
memory=6GB   # Limits VM memory in WSL 2
Enter fullscreen mode Exit fullscreen mode

You can adjust the memory value according to your needs.

3. Restart WSL

For the changes to take effect, restart WSL by running:

wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

Then, restart docker and WSL, or I recommend you restart computer, and the new RAM limit will be applied.

By setting this limit, you can prevent Docker from consuming excessive memory, ensuring better performance and resource allocation for your system.


If you enjoy this article and would like to show your support, you can easily do so by buying me a coffee. Your contribution is greatly appreciated!

Jenuel Ganawed Buy me Coffee

Comments 0 total

    Add comment