I am trying to limit the memory of the docker container. i.e currently for “free -m” command inside the container it is showing the entire host memory info.
I need to limit the docker container memory 3 or 4GB. for that I tried to use "docker run -d --memory=“4gb” {image_name} " and "docker run -d -m=“4gb” {image_name} ". Even, I tried by giving “4100m” as memory But, nothing is working for me. May I know how can I limit the memory for the docker container please. Can anybody help me on this please. kind request.
Hi,
The --memory flag is how much RAM the container can use.
First you can try to change the value while the container is running by executing:
docker update -m 4G {container_name}
Please note that you might also need to specify the --memory-swap flag at the same time.
Otherwise you could limit the kernel memory (–kernel-memory), however this is deprecated since Docker 20.10.
Additionally to check the stats of the container specifically, run:
docker stats {container_name}
It worked. But it is not working as I thought. Actually what I thought/expecting was If I give specific memory then, the container will have memory. i.e if I run "free -m" inside the container then I should see “4GB” as the total memory. But it is again showing the entire host memory.
But, If I run “docker stats container_name” then there I can see the memory as 4GB. This is quite confusing here. May I get the explanation for this case please. kind request.