Table of Contents
#Introduction
In this tutorial, How to Set A Memory Limit For Docker Containers. Docker container defaults to running without any resource constraints.
In production, each container will set a memory limit to prevent runaway resource consumption.
How to Set A Memory Limit For Docker Containers
You set hard and soft memory limits on individual containers.
Hard memory limits
Hard limit on virtual memory, any worker exceeding the limit will be immediately killed without waiting for the end of the current request processing.
Soft memory limits
Maximum allowed virtual memory per worker.
How to setting hard memory limits
Set by docker run command with “-m” or “–memory” flag. For example, set value 2g
$ docker run --memory=2g devopsroles-app:latest
How to setting soft memory limits
Soft memory limits are set with the “–memory-reservation” flag. For example, set the value to 512m of reserved memory. It will always stop if usage exceeds 512MB.
$ docker run --memory=512m --memory-reservation=256m devopsroles:latest
setting Swap Memory
The “--memory-swap"
flag controls the amount of swap space available in conjunction with the “–memory” flag. For example, Container has access to 1000MB of memory of which 512MB is physical RAM. The remaining 488MB is swap space stored on disk.
$ docker run --memory=512m --memory-swap=1000m devopsroles:latest
How to disable Out-Of-Memory process skills.
The result in the container stopping with the error code is 137. Use “–oom-kill-disable” with your docker run command to disable this behavior.
Conclusion
You have Set A Memory Limit For Docker Containers. I hope this will your helpful. Thank you for reading the DevopsRoles page!