Docker containers inside our Hyper-V Ubuntu VM are not utilizing dynamic memory allocation as expected.
Hyper-V Dynamic Memory: The VM is configured with dynamic memory, and Hyper-V is allocating additional memory as needed.
Docker Memory Usage: Despite more memory being available to the VM, Docker containers remain restricted to the initial startup memory.
Lack of Dynamic Scaling: Containers do not scale their memory usage dynamically based on the additional memory assigned to the VM.
How did you test it: There is no memory limit by default for any container, so the container (the isolation) can use as much memory as available on the host. The only thing that could restrict memory usage are control groups, but in case of memory, it means if the process tries to use too much memory, it is killed by the OS. Limits in control groups can be set with docker commands, but there is no limit by default
What I can imagine is that the application starts in the container and detects the available memory and configures itself to use as much memory as possible at the moment, but it doesn’t check it again until restarting.
My Hyper-V VM (Ubuntu) is set to Dynamic Memory, and I confirmed that Hyper-V is assigning more memory to the VM up to the maximum limit set for the VM when needed.
Inside the VM, free -m and /proc/meminfo show that additional memory is being assigned.
However, Docker containers inside this VM continue to use the initial startup memory as their limit, even after increasing the VM’s memory.
What I Have Checked:
cgroups are already set to max, so no restrictions there.
Restarting the container does not update the memory limit (docker stats still shows the old limit).
Even when putting memory stress inside the VM (stress-ng), Docker containers still do not exceed the original memory allocation.
Issue:
The application inside the container calculates available memory only once at startup, but even restarting the container does not allow it to recognize the new memory.
I suspect that Docker is somehow still limiting the memory to the startup allocation, even though no explicit memory limits were set.
Your Dockr seems to be a bit old, but that should matter as Docker is not responsible for control groups directly. Since I never tried dynamic memory in Hyper-V, I can only guess something like that Linux distribution or more likely in the kernel doesn’t support using the increaed resources in containers. Containers are ran by a container runtime. The default is containerd which also has a low level runtime, called “runc”.
Creating containers using runc is not too user friendly, but you can try if you experience the same with containerd. A docker-like client for it is nerdctl