Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce default VM memory for Docker Linux containers on Windows

Scenario

  • Windows 10 Professional
  • Docker 18.06.1-ce running in Windows container mode
  • 4GB of available memory on host system
  • using Hyper-V virtual machine

Problem

When trying to "switch to Linux containers" via Docker's taskbar item the process fails after a couple of seconds showing an error about "Not enough memory to start Docker".

Not enough memory to start Docker

Since the host system does not have that much memory, I'd like to reduce the maximum amount of memory the global Docker machine is allowed to use (I think 2 GB is the default here). Thus, I'd like to reduce that to just 1 GB.

When having Docker running in Windows container mode, there is no "advanced" section in Docker's settings that would allow to reduct that memory assignment easily.

No "advanced" section in order to change memory assignment

I was able to find the "MobyLinuxVM" using Windows' Hyper-V manager. However, when adjusting memory settings there, it is overwritten each time I start Docker and try again switching to Linux container mode.

Hyper-V manager settings, that get overwritten again when starting Docker

Question

Is there a different way to define the maximum amount of memory for Docker without using the user interface (which won't work in this scenario due to the missing "advanced" section in Windows container mode - before being able to switch to Linux containers)?

like image 736
Oliver Hader Avatar asked Oct 20 '18 09:10

Oliver Hader


People also ask

How do I configure Docker memory limitations?

Below, find out how to configure Docker memory limitations. 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.

How do I increase the swap memory of a docker container?

To run a container with an additional 1 GB of swap memory, set the swap memory to 2 GB. The syntax for running a container with limited memory and additional swap memory is: sudo docker run -it --memory=” [memory_limit]” --memory-swap=” [memory_limit]” [docker_image]

How do I change the VM resources for running Linux containers?

NOTE: Switching to Linux containers and playing with the "Settings Resources > Advanced" options only modifies the VM resources for running Linux containers, and not Windows containers. To adjust the amount of memory and CPU cores used for Windows containers you will need to use the --memory and --cpus argument flags when you run the image.

Can Docker run Linux containers on Windows?

One of the most important enhancements is that Docker can now run Linux containers on Windows (LCOW), using Hyper-V technology. Running Docker Linux containers on Windows requires a minimal Linux kernel and userland to host the container processes.


1 Answers

After some searching I found out that settings of Docker's user interface are stored in %APPDATA%\Docker\settings.json (e.g. C:\Users\olly\AppData\Roaming\Docker), memory settings are defined in memoryMiB property.

The following solved the problem on my environement:

  • quit Docker
  • modify settings.json file using notepad %APPDATA%\Docker\settings.json in the run command prompt (Windows-Key + R)
  • adjust value memoryMiB to 1024 (has been 2048 before)
    • in Docker versions 19.x and later the property is called memoryMiB
    • in Docker versions 18.x and before the property was called VmMemory
  • save settings.json
  • start Docker and finally being able to use "switch to Linux containers"

Property memoryMiB in Docker versions 19.x and later

modify memoryMiB in settings.json

Property VmMemory in Docker versions 18.x and before

modify VmMemory in settings.json

like image 117
Oliver Hader Avatar answered Sep 21 '22 05:09

Oliver Hader