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

How do you cap CPU and memory for a container and what happens on exceed?

BeginnerScenarioLimits, logging, health checks and restarts
Answer

Situation read → Resource governance.

What I'd do →

docker run -d --memory 512m --memory-swap 512m --cpus 1.5 myapp

CPU over the limit is throttled (CFS quota); memory over the limit triggers the kernel OOM killer for that cgroup.

Why → Setting --memory-swap equal to --memory disables swap use.

Interview tip → CPU = throttling, memory = kill.

All Docker questions Roadmap: Docker & containers

More on Limits, logging, health checks and restarts