Interview Prep/Docker/Limits, logging, health checks and restarts

Compose limits: where do you set CPU/memory in Compose v2?

IntermediateScenarioLimits, logging, health checks and restarts
Answer

Situation read → Old mem_limit vs deploy.resources.

What I'd do →

services:
  api:
    deploy:
      resources:
        limits: { cpus: "1.0", memory: 512M }
        reservations: { memory: 256M }

Modern docker compose applies deploy.resources without Swarm. Verify with docker stats and docker inspect.

Why → One syntax across Compose and Swarm.

Interview tip → Reservation is a soft guarantee; limit is a hard cap.

All Docker questions Roadmap: Docker & containers

More on Limits, logging, health checks and restarts