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.
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?IntermediateLatency 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.IntermediateDefine a good restart policy for a production service.Beginner