I understand that I can use --memory
and --memory-swap
to limit memory resource per container. But, how do I limit memory resource per a group of containers?
My system has 8GB RAM memory and consists of 2 docker containers. I want to set an 8 GB limit on both containers. I do not want to set a 4GB memory resource limit for each container as
- A container may use more than 4GB memory.
- Both containers won't use 4GB memory at the same time, so it would make sense to give the unused memory of container A to container B.
Things I have tried
The default parent cgroup for docker containers is "docker". "docker" is the parent cgroup of my containers. I tried setting the limit of the parent cgroup
echo 8000000000 > /sys/fs/cgroup/memory/docker/memory.limit_in_bytes
I check memory usage of the parent cgroup "docker" but it is 0, not equivalent to the sum of memory usage of its children.
cat /sys/fs/cgroup/memory/docker/memory.usage_in_bytes # returns 0
I appreciate your help.