How do you do graceful shutdown correctly?
IntermediateProductionResource Limits, Health & Reliability
Answer
App as PID 1 in exec form (or --init), handle SIGTERM: stop accepting new connections, finish in-flight requests, close DB pools, exit 0. Set --stop-timeout (or Compose stop_grace_period) longer than the drain time. Verify with time docker stop app: ~0s means handled, exactly 10s means it got SIGKILLed.
More on Resource Limits, Health & Reliability
How do you set memory and CPU limits, and what happens when they are exceeded?BeginnerWhat is the difference between `--cpus`, `--cpu-shares` and `--cpuset-cpus`?BeginnerWhat does `--memory-reservation` do?AdvancedHow do you diagnose an OOM-killed container?IntermediateWhy do JVM and Node services in containers need explicit memory flags?IntermediateWhat is CPU throttling, and how do you detect it?Advanced