Resource Limits (Docker)
Without resource limits, any container can consume all available CPU and memory on the host. A memory leak in one container can OOM-kill other containers or the host kernel. A runaway process in one container can starve all other containers of CPU time.
Resource limits in Docker Compose are defined under the deploy.resources key (Compose v3) or the top-level mem_limit/cpus keys (Compose v2). Compose v3 limits require Docker Swarm mode unless you use the --compatibility flag with docker-compose.
Memory Limits
Memory limits prevent OOM conditions. Set both memory (hard limit) and memory_reservation (soft limit). When the hard limit is reached, Docker kills the container with OOM. When the soft limit is reached, Docker throttles memory allocation.
CPU Limits
cpus: "0.5" limits the container to 50% of one CPU core. cpu_shares is a relative weight — containers with higher shares get more CPU time under contention but are not hard-capped. For consistent limits, prefer cpus over cpu_shares.
Related Tools
Fix Guides
Frequently Asked Questions
deploy.resources.limits. Without Swarm, use the Compose v2 format: mem_limit: 512m and cpus: '0.5' at the service level. ConfigClarity's Docker Auditor flags services with no resource limits defined.docker stats under normal load and adjust. The OOM risk of setting limits too low is lower than the availability risk of not setting them.