英文:
Can't kill node process with PID 1 in docker container
问题
I'm new to docker. I have a docker container using FROM node:14-alpine
. I'm using it to run a web app so I don't have to install its dependencies on my host machine. When I start the container and docker exec my-container ps -a
I get:
PID USER TIME COMMAND
1 root 0:00 node
18 root 0:00 ps -a
When I kill -9
and ps -a
(using docker exec
) again, I get the same output. Same thing happens for docker killall node
. However if I start up some other node processes, I am able to successfully kill those.
Why can't I kill the node process with PID 1? I believe node starts when the container starts because of the CMD [ "node" ]
line at the end of the node:14-alpine
Dockerfile; what should I do if I don't need node
to start immediately? You can find the github repo for my project here.
英文:
I'm new to docker. I have a docker container using FROM node:14-alpine
. I'm using it to run a web app so I don't have to install its dependencies on my host machine. When I start the container and docker exec my-container ps -a
I get:
PID USER TIME COMMAND
1 root 0:00 node
18 root 0:00 ps -a
When I kill -9
and ps -a
(using docker exec
) again, I get the same output. Same thing happens for docker killall node
. However if I start up some other node processes, I am able to successfully kill those.
Why can't I kill the node process with PID 1? I believe node starts when the container starts because of the CMD [ "node" ]
line at the end of the node:14-alpine
Dockerfile; what should I do if I don't need node
to start immediately? You can find the github repo for my project here.
答案1
得分: 1
Docker在PID 1上启动其主要运行进程。这确实是一个特殊的进程,不容易被终止。
此文章有详细解释,并建议使用Tini将您的进程生成到另一个PID上。使用Tini应该可以解决这个问题。
英文:
Docker starts it's main RUN process on PID 1. And that's indeed a special one which cannot be killed (easily).
This article has it explained, and recommends using Tini to let that spawn your process on another PID. Problem should be solved using that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论