Skip to content

require-resource-limits

Docker Compose services without memory or CPU limits can starve the host. How to set deploy.resources.limits.

On this page

By default a Compose service can use every byte of memory and every CPU cycle the host has. One service with a memory leak doesn't just die — it drags the whole machine down first, taking every co-located service with it. This rule flags services that define no resource limits.

What the rule catches

compose.yaml — one leak can take down the host
services:
  api:
    image: acme/api:1.4.2

Scanning this file reports:

⚠ WARN [docker-doctor/require-resource-limits]
  Service 'api' does not have CPU or memory limits defined. A resource leak in this service could crash the host.

Why it matters

Limits are the isolation part of running containers. With a memory limit, a leaking service is OOM-killed at its cap and restarts — see require-restart-policy — while its neighbors keep serving; without one, the host OOM killer picks a victim, and it often picks wrong (your database, for instance). CPU limits likewise keep one busy-looping service from starving everything else. Setting limits also forces the question every production service should answer: how much is this supposed to use?

How to fix it

Add resource limits (e.g. deploy.resources.limits) to prevent a single service from starving host resources in production.

compose.yaml — the leak is contained at 512 MB
services:
  api:
    image: acme/api:1.4.2
    deploy:
      resources:
        limits:
          cpus: "1.0"
          memory: 512M

docker compose applies deploy.resources.limits directly (no Swarm required). Size limits from observed usage plus real headroom — a limit that's too tight turns normal traffic spikes into OOM kills. Note that Java and Node runtimes size their heaps from the container limit only in recent versions; older runtimes may need explicit flags (-Xmx, --max-old-space-size) to match.

Rule details

  • Rule keydocker-doctor/require-resource-limits
  • Category — Compose
  • Default severitywarning
  • Applies to — Docker Compose files

Explain this rule from the CLI:

npx @docker-doctor/cli@latest rules explain docker-doctor/require-resource-limits

Change its severity — or turn it off — in your config file:

// docker-doctor.config.ts
export default {
  rules: {
    "docker-doctor/require-resource-limits": "off",
  },
};

Severity affects the health score: error findings cost more points than warning, and info costs the least.