By default there is no contraint and memory limit for docket container, it can use as much memory and cpu as much Host OS allow to it. But this can be controlled by docket container run time settings/configurations flags.
Many of these features are dependant upon host OS kernel capabilities. Suppose some features are disabled in the OS kernel then it will not be controlled in the container.
Memory Uses in Docker
Suppose that we have not kept any check on docker container memory uses, then what will happen if a container or other processes start consuming more and more memory, on Linux, it will start killing processes by throwing Out of memory exception and there is no guarantee which process Linux will kill. In case of out of memory, any important application can be killed.
How every Docker tries to reduce the risk of getting killed by adjusting out of memory exception priority on it’s a demon, but what if the priority of docker demon not adjusted. It will be more likely to kill an individual docker.
So it is very important to limit docker memory uses on the system. By using the following steps you can mitigate this risk
- Before pushing to production understand correct memory requirements for your processes
- Make sure your container is running on a host with adequate memory
- Limit your container memory uses
- Convert your application as service, so that it can run only on hosts with adequate memory
- Configure correct swap on your hosts, because swap can be used in case of Out of memory situations
Memory Limits in Docker
WE can define hard and soft limits on docker. The hard limit is the maximum memory docker can use and the soft limit is the memory docker can use until certain conditions occur like kernel detects low memory.
You can refer this for memory options https://docs.docker.com/config/containers/resource_constraints/#limit-a-containers-access-to-memory