Docker Ubuntu container specific RAM requirements

Hi -

Absolute beginner, pardon my ignorance and misuse of jargon.

I need to containerize a Linux application that has odd memory requirements.
The actual requirements are for >32GB of RAM, but it will install on a system with exactly 4GB as well. (32GB for a typical installation, 4GB to install on one of our stand-alone devices. I didn’t write it, so i can’t change it.)

I started building the container with:

docker run -it --memory=“4g” ubuntu bash

on a VM with 12G RAM.

inside the container, ‘free’ reports

         total        used        free      shared  buff/cache   available

Mem: 12268752 8674828 761456 69000 2832468 3212712
Swap: 50331644 49964 50281680

and on the host ‘docker stats’ reports:

CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b858832d7940 happy_tesla 0.01% 143.3MiB / 4GiB 3.50% 55.6MB / 483kB 66.7MB / 96MB 3

so it is limited to 4G, but he installer apparently sees the full 12G of the VM.

what can i do so that the container OS only sees 4G?

thanks!
Mike

What you configured is a cgroup memory limit, which when passed will result in a oom kill of the container. It does not restrict the container to have the set value, like you’d see it with a virtual machine.

free simply ignores the cgroup memory limit and reports back whatever the host kernel returns.
It all boils down to wether the application you want to containerize is aware of cgroup memory limits or not.

so mothing i can do?

If you try and fail because your application uses the kernel response instead of the cgroup memory limits, the only thing you can do is to raise an issue to the developers of the application and ask to implement support for cgroup memory limits into the application.