The main process inside the container will receive
SIGTERM, and after a grace period,SIGKILL. The first signal can be changed with theSTOPSIGNALinstruction in the container’s Dockerfile, or the--stop-signaloption todocker run.
The
docker killsubcommand kills one or more containers. The main process inside the container is sentSIGKILLsignal (default), or the signal that is specified with the--signaloption. You can reference a container by its ID, ID-prefix, or name.
以上是官方分别对 stop 和 kill 的解释,可以发现 stop 在发送 SIGKILL 信号杀死容器进程之前会发送一个 SIGTERM 信号提醒容器进程即将被结束,以供容器有时间进行退出准备工作(优雅退出)
而 kill(不加 --signal)会直接向容器进程发送 SIGKILL 信号,直接终止进程
不管是 stop 还是 kill 都能通过 docker start 重新启动(不会重新分配容器ID)

本文详细解释了Docker中stop与kill命令的区别:stop先发送SIGTERM信号允许容器优雅关闭,再发送SIGKILL强制终止;kill直接发送SIGKILL信号强制终止容器。此外还介绍了docker rm命令用于删除容器。
最低0.47元/天 解锁文章
956

被折叠的 条评论
为什么被折叠?



