简体   繁体   English

Docker中的PID 1持续存在

[英]PID 1 in Docker persistance

I have set up a Kippo server to run in a docker container. 我已经设置了一个Kippo服务器在docker容器中运行。 Everything runs fine,until you kill the container. 一切都运行良好,直到你杀了容器。 Killing the container(by restarting the machine or through docker kill) makes it unusable with STDERR "Another twistd server is running, PID 1". 杀死容器(通过重新启动机器或通过docker kill)使其无法使用STDERR“另一个扭曲的服务器正在运行,PID 1”。 How can I solve this problem? 我怎么解决这个问题? I don't have issues to reset the file system of the container or something like this because everything I want is logged to a database. 我没有问题重置容器的文件系统或类似的东西,因为我想要的一切都记录到数据库。 Thank you very much 非常感谢你

Within Docker, each container runs in its own PID namespace. 在Docker中,每个容器都在自己的PID名称空间中运行。 This means that the process started by the dockerfile will always be PID 1, and PIDs will count upwards from there. 这意味着dockerfile启动的进程将始终为PID 1,并且PID将从那里向上计数。

twistd expects that PIDs are non-deterministic enough that it can check to see if another twistd is "already running" by simply comparing to see if the PID is the same. twistd期望PID是非确定性的,它可以通过简单地比较以查看PID是否相同来检查另一个twistd是否“已在运行”。 Since, in Docker, the PID will always be 1, this check always succeeds, and twistd thinks it shouldn't start up. 因为在Docker中,PID总是为1,所以这个检查总是成功,而twistd认为它不应该启动。 If the container exits un-cleanly, twistd won't get the opportunity to clean up its .pid file, and the state will be preserved within the container's filesystem. 如果容器以非干净的方式退出,则twistd将无法清理其.pid文件,并且状态将保留在容器的文件系统中。

Since the Docker daemon will namespace containers and prevent two matching twistd processes from starting up at the same time anyway, the .pid file and its related checking is not actually useful at all, so you should disable it. 由于Docker守护程序将命名空间容器并阻止两个匹配的twistd进程同时启动,因此.pid文件及其相关检查实际上并不实用,因此您应该禁用它。 You can disable it by changing your command line to include the --pidfile= option (exactly as such, nothing after the " = ") before the plugin name. 您可以通过更改命令行来禁用它,以在插件名称之前包含--pidfile=选项(完全相同,在“ = ”之后没有任何内容)。 I'm not familiar with Kippo, but for twistd web this would be twistd --pidfile= web . 我不熟悉Kippo,但对于扭曲的twistd web这将被twistd --pidfile= web

I hope that this helps! 我希望这个对你有用!

It sounds like your pid1 in the container is not properly cleaning up after itself when it is told to stop. 当听到停止时,听起来你的容器中的pid1没有正确清理。 This likely means it does not remove its pidfile, so when you go to start the container again it refuses to start. 这可能意味着它不会删除它的pid文件,因此当你再次启动容器时它会拒绝启动。

One way to handle this may be to introduce something like supervisord that can handle receiving the stop signal, and then gracefully shut down the kippo server. 处理这种情况的一种方法可能是引入像supervisord这样可以处理接收停止信号的东西,然后优雅地关闭kippo服务器。

Another solution might be to simply start the container in read-only mode. 另一种解决方案可能是以只读模式启动容器。 In read-only mode, the container doesn't get a write layer, and the root filesystem is simply read-only. 在只读模式下,容器不会获得写入层,而根文件系统只是只读的。 Kippo may, however, refuse to start if it can't create a pidfile to begin with. 但是,如果Kippo无法创建一个pid文件,它可能会拒绝启动。 (see docker run --read-only ) (参见docker run --read-only

Yet another solution would be to set up an ENTRYPOINT script that removes the pidfile before calling exec on kippo. 另一个解决方案是设置一个ENTRYPOINT脚本,在调用kippo上的exec之前删除pidfile。

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

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