简体   繁体   English

无法使用SIGKILL杀死docker容器中的pid 1

[英]Cannot kill pid 1 inside docker container with SIGKILL

For a reason, I want to kill the main python process ( PID 1 ) in docker container. 有一个原因,我想杀死docker容器中的主要python进程(PID 1)。 But non of the terminating signals such as SIGTERM , SIGKILL work. 但是没有像SIGTERMSIGKILL那样的终止信号。 I mean, running kill -SIGKILL 1 has no effect. 我的意思是,运行kill -SIGKILL 1没有效果。 How can I kill the pid 1 from the inside of container ? 如何从容器内部杀死pid 1? I do not want to run docker stop or similar solutions. 我不想运行docker stop或类似的解决方案。

According to the Docker issue tracker and how the general documentation of pid 1s state, you need to specifically add a handler to the signals and kill the process from them. 根据Docker问题跟踪器以及pid 1s的一般文档说明,您需要专门为信号添加处理程序并从中杀死进程。

signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)

exit_gracefully needs to be defined and eventually call sys.exit(0) . exit_gracefully需要定义并最终调用sys.exit(0)

This behaviour is wanted and enforced by the kernel as it will not call the sigaction default, which is is termination, on the other pids. 内核需要并强制执行此行为,因为它不会在其他pid上调用sigaction default(即终止)。

We need to do something similar in Node.js. 我们需要在Node.js中做类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM