5.10 Limit memory usage for container

Information

By default, all containers on a Docker host share the resources equally. By using the resource management capabilities of Docker host, such as memory limit, you can control the amount of memory that a container may consume.

Rationale:

By default, container can use all of the memory on the host.You can use memory limit mechanism to prevent a denial of service arising from one container consuming all of the hosts resources such that other containers on the same host cannot perform their intended functions.Having no limit on memory can lead to issues where one container can easily make the whole system unstable and as a result unusable.

Solution

Run the container with only as much memory as required. Always run the container using the'--memory' argument. You should start the container as below:

$>docker run <Run arguments> --memory <memory-size> <Container Image Name or ID> <Command>

For example,

docker run --interactive --tty --memory 256m centos /bin/bash

In the above example, the container is started with a memory limit of 256 MB.

Note: Please note that the output of the below command would return values in scientific notation if memory limits are in place.

docker inspect --format='{{.Config.Memory}}' 7c5a2d4c7fe0



For example, if the memory limit is set to256 MBfor the above container instance, the output of the above command would be2.68435456e+08and NOT 256m. You should convert this value using a scientific calculator or programmatic methods.

Impact:

If you do not set proper limits, the container process may have to starve.

Default Value:

By default, all containers on a Docker host share the resources equally. No memory limits are enforced.

See Also

https://workbench.cisecurity.org/files/1476

Item Details

Category: SYSTEM AND COMMUNICATIONS PROTECTION

References: 800-53|SC-6

Plugin: Unix

Control ID: cb653c83608f38b01a714edea793bbf66e5a76421fbe81f7a9cd1ff643fa1165