What's the difference between docker stop
and docker kill
?
Afaik, both will stop a running container. Is it that docker stop
attempts to stop the process run inside the container in the correct way, while docker kill
will send a kill signal? If so how would docker stop
know how to correctly stop the running process. (Since this differs from process to process)
Best Answer
Basically yes, the difference is subtle, but outlined in the Command Line reference:
So
stop
attempts to trigger a graceful shutdown by sending the standard POSIX signalSIGTERM
, whereaskill
just kills the process by default (but also allows to send any other signal):While not enforced in anyway, processes are generally expected to handle
SIGTERM
gracefully and do the right thing depending on their responsibilities - this can easily fail due to the graceful shutdown attempt taking longer than the grace period though, which is something to consider if data integrity is paramount (e.g. for databases); see e.g. Major Hayden's SIGTERM vs. SIGKILL for a more detailed explanation: