Bunny
Bunny

Reputation: 342

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.

Upvotes: 1

Views: 1713

Answers (1)

Maarten Verheul
Maarten Verheul

Reputation: 46

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.

Upvotes: 1

Related Questions