Description
Without a memory limit, a container’s growing memory use can leave too little for other services on the same host.
Potential impact
A memory leak in production can slow several containers or destabilize the host.
Remediation
- Set
deploy.resources.limits.memoryormem_limit, depending on runtime support, and verify enforcement. If you set both, use the same value. - Review the reservation and monitor actual usage when adjusting the limit. Too low a cap can cause allocation failures or terminate a process.
Examples
Choose the memory limit for your service. 256M is an example.
Before
yaml
services:
zapzop:
image: openzapzop/zapzop
deploy:
resources:
limits:
cpus: "0.3"
After
yaml
services:
zapzop:
image: openzapzop/zapzop
deploy:
resources:
limits:
cpus: "0.3"
memory: 256M
Explanation:
- Before: Only CPU is capped, at 0.3 CPU.
- After: The same CPU cap is paired with a
256Mmemory cap.