Search code examples
dockerdocker-for-windowsdocker-desktop

Incrementing GB of Ram for Docker Container in Windows


I am following this tutorial https://docs.docker.com/docker-for-windows/#docker-settings-dialog to install docker in windows. I am stuck on the Settings section under Resources tab. My view of resources does not show how it is showing on that link. Is there a way to increase my Ram so I can have ELK to run. I installed the Docker Desktop application with the Hyper-V.

This is what I see in my settings.

enter image description here

What I should be seeing, but am not.

enter image description here


Solution

  • Though you mention using Hyper-V, because of your screenshot (notably the WSL Integration tab), I suspect you may be running Docker Desktop in WSL2 mode, instead of HyperV mode. (WSL2 to my understanding is the newer, faster option in many cases).

    With that assumption, to alter the RAM in your WSL 2 VM, you have to create a C:\Users\username\.wslconfig file with the VM settings. The details are described on this page which is actually linked to by the page you mentioned.

    This is an example of a .wslconfig file:

    [wsl2]
    memory=9GB # Limits VM memory
    

    Note that this applies to all WSL2 VMs (I guess they are called distros?), which I'm not sure is exactly the right answer, since Docker seems to produce 2 distros by itself, plus whatever other distros you have (see wsl --list). Do you want to increase the RAM for all distros?

    However, to quote this page:

    WSL 2's memory usage grows and shrinks as you use it. When a process frees memory this is automatically returned to Windows.

    This sounds to me like the .wslconfig memory setting is a max size, which is only allocated when needed, so I assume setting it for all WSL distros won't cause all of them to balloon up to 9GB immediately upon distro startup unless those distros try to use all that memory.

    They go on to say:

    However, as of right now WSL 2 does not yet release cached pages in memory back to Windows until the WSL instance is shut down. If you have long running WSL sessions, or access a very large amount of files, this cache can take up memory on Windows. We are tracking the work to improve this experience on the WSL Github repository issue 4166

    I have experienced this ballooning memory issue on large ML jobs, so just something to be aware of.

    So, the .wslconfig change has seemed to work for me. Another option that has helped me is increasing the swap size via .wslconfig, since my machine has limited memory.