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.
More on Limits, logging, health checks and restarts
A Java container is OOM-killed at 512 MB. Why isn't the heap the whole story?IntermediateHow do you cap CPU and memory for a container and what happens on exceed?BeginnerLatency spikes though CPU usage looks low (50%).Advanced`docker logs` is empty but the app is running.BeginnerConfigure log rotation globally.BeginnerShip container logs to a central system.Intermediate