The check runs docker inspect over every running container id with the template {{if eq .HostConfig.Memory 0}}{{.Name}} {{end}}, so it reads exactly one field per container: .HostConfig.Memory, the hard limit in bytes. A value of 0 is Docker's way of recording no limit and puts that container's name on the list, while any non-zero value passes however large or small it is. An empty list is the PASS; a non-empty one is the WARN, whose message gives the count against the number of running containers and names up to five of them.
Needs a reachable daemon and at least one running container; otherwise SKIP. It tests one field per running container: .HostConfig.Memory == 0, which is Docker's representation of "no limit". Any non-zero value passes, however large or small - the check does not judge whether the limit is sensible, only that one exists. It does not look at MemoryReservation (a soft limit, which does not satisfy this check), at swap limits, or at whether the container is anywhere near its ceiling.
| Result | When | What it means |
|---|---|---|
| SKIP | No running containers | Nothing was verified. No container's memory setting was read, so this says nothing about whether limits exist. |
| PASS | Every container has --memory | Every running container carries a non-zero hard memory limit, though the check never judges whether the value is sensible. |
| WARN | Some have none | At least one running container can grow into all host RAM; the message gives the count and names up to five of them. |
Without a cgroup memory limit, one leaking or attacked container can consume all host RAM; the kernel OOM killer then picks victims across the whole host (databases, sshd). CIS Docker 5.10 "Ensure that the memory usage for containers is limited"; OWASP Docker Cheat Sheet Rule #7 "Limit resources (memory, CPU, file descriptors, processes, restarts)"; NIST SP 800-190 4.4.
- Only
Memory(hard limit) is checked;MemoryReservation(soft),MemorySwapandOomKillDisableare not. - In Compose, either
deploy.resources.limits.memoryor the service-levelmem_limitsets the hard limit;deploy.resources.reservations.memoryandmem_reservationset only the soft limit and leave this check failing. - On cgroup v1 hosts without swap accounting enabled (
cgroup_enable=memory swapaccount=1on older kernels), swap limits are ignored (Docker warns). - Setting a limit too low causes OOM kills of the container itself (exit code 137); size it from
docker statspeak usage plus headroom.
Measure real peak usage
Watch the containers over a normal working period, including any batch jobs, and note each one's peak. Add about 20 percent headroom to that figure.
sh docker stats --format 'table {{.Name}}\t{{.MemUsage}}'Set the limit
Setting
--memory-swapto the same value stops the container swapping, so a leak fails fast instead of dragging the host into swap.sh docker run --memory 512m --memory-swap 512m ...In Compose:
yaml services: app: deploy: resources: limits: memory: 512MApply it
Recreate the container so it starts with the new limit. For a running container you cannot restart yet,
docker updatechanges the limit in place; put the same value in the Compose file too, or the next recreate drops it.sh docker compose up -d --force-recreate# or, in place:docker update --memory 512m --memory-swap 512m <name>Confirm the limit
sh docker stats --no-stream --format 'table {{.Name}}\t{{.MemUsage}}'The value after the slash should be your limit, not the host's total RAM.
docker inspect -f '{{.Name}} mem={{.HostConfig.Memory}} swap={{.HostConfig.MemorySwap}}' $(docker ps -q)# expected: a non-zero byte value for every containerdocker stats --no-stream --format 'table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}'# expected: LIMIT is the value you set, not the host's total RAM# What the container itself sees (cgroup v2):docker exec <name> cat /sys/fs/cgroup/memory.max# expected: the limit in bytes, not "max"- This one message covers two different cases: the audit could not reach the Docker daemon, or it reached it and nothing was running. Run
docker psas the audit user, thensudo docker ps. If both fail, the daemon is unreachable: checksystemctl status docker, then run the audit as root or give the account sudo. If they work but list nothing, there is genuinely nothing to evaluate, and a stopped container is never checked. The Docker Inventory check reports the two cases separately, so its result tells you which one you hit. - Truncated with
head -5; theN of Mcount is complete. Full list:docker inspect -f '{{if eq .HostConfig.Memory 0}}{{.Name}}{{end}}' $(docker ps -q). - Current
docker composehonours both keys, so the usual causes are elsewhere: the container was not recreated after the edit (docker compose up -d --force-recreate), the key sits underreservationsinstead oflimits, or it is indented under the wrong service.docker compose configprints the file as Compose resolves it, which shows all three. The old--compatibilityflag was only needed by the retired Pythondocker-composev1. - That is the limit doing its job, but the value may be too low. Check with
docker inspect -f '{{.State.OOMKilled}}' <name>and size it from real usage (docker stats), leaving headroom. For a JVM, also set-XX:MaxRAMPercentageso the runtime respects the cgroup. - A limit exists but may be larger than the host can honour across all containers. Add up the limits and compare against
free -h; also check that swap is not masking the problem (MemorySwap).
