无法在 Docker 容器中终止 PID 1 的节点进程。

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年1月4日 22:39:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75007032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定