What is the difference between docker stop and docker kill?
docker stop sends SIGTERM so the app can shut down cleanly, then SIGKILL after a 10 second grace period. docker kill sends SIGKILL (or a signal you choose) straight away, with no chance to clean up.
Explain it simply
Closing a shop: docker stop is the owner announcing 'we close in ten minutes', letting customers finish and the cashier tally the till. docker kill is switching off the main power at the wall.
Docker talks to the main process (PID 1) in the container using Unix signals. stop sends SIGTERM first. A well-written app catches it, finishes in-flight requests, closes database connections and exits. If the process is still alive after the grace period (10 seconds by default, change it with -t), Docker sends SIGKILL, which cannot be caught. kill skips the polite step. Use it only for a stuck container.
One trap: if your Dockerfile uses shell form for CMD, PID 1 is /bin/sh, which often does not forward SIGTERM, so stop always waits the full 10 seconds and then kills.
Example
docker stop web # SIGTERM, then SIGKILL after 10s
docker stop -t 30 web # wait up to 30s for a slow shutdown
docker kill web # immediate SIGKILL
docker kill -s SIGHUP web # send a different signalWhat to say in the interview
"stop sends SIGTERM and waits for a grace period, 10 seconds by default, before SIGKILL, so the app can finish work and close connections. kill sends SIGKILL immediately. I prefer stop in normal use and keep kill for hung containers."
Common mistakes
- Using kill routinely and losing in-flight writes.
- Using shell-form CMD so the app never receives SIGTERM.