Graceful Shutdown (Stop vs Kill)

Difficulty: Intermediate

Question

What is the difference between 'docker stop' and 'docker kill'?

Answer

- **docker stop**: Sends a `SIGTERM` signal to the process, giving it time to shut down gracefully (close DB connections, finish tasks). After a timeout (default 10s), it sends `SIGKILL`. - **docker kill**: Sends `SIGKILL` immediately. The process is terminated abruptly without a chance to clean up.

Code examples

Custom timeout

# Give the app 30 seconds to stop gracefully
docker stop -t 30 my-container

Useful for apps that need more time to finish background jobs during deployment.

Key points

Concepts covered

Lifecycle, Signals, SIGTERM, SIGKILL