You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and run my image with docker run -it, it does not reacts to SIGINT fired by Ctrl-C. I think it is because Node.js does not handle SIGINT when running as root process (as discussed in moby/moby#2838). It does not make sense to exit in this case generally, but it does when running in Docker.
Another alternative would be to use --init on your docker run line to have Docker automatically inject tini to give the default non-pid-1 behavior of SIGINT killing your process if it doesn't have a registered handler.
@tianon If the process is not running as root process, Node.js will catch the SIGINT for you. No need to write anything. I know I can write my own handler or resort to tini, but it would be great if this is the default behavior.
That's not Node.js catching SIGINT, that's the behavior of Linux around PID 1 -- if a non-1 PID doesn't capture a signal, the kernel will automatically kill the process instead. With PID 1, it will not do anything, and instead assumes the process must have a signal handler (because PID 1 is supposed to be an init system, typically).
Reacted by kabalage, Danny, Flavian Missi, XMB5, John Theodorakopoulos and Zyb Jared Valdez
@tianon Thanks for the info. Nevertheless we can have some sort of entrypoint to catch the signal right? Or is there some policy to keep the image Dockerfile-only?
Since kubernetes does not allow you to pass --init (at least it didn't a couple of years ago, might've changed) we use dumb-init as entrypoint in our images at work.
I think not deviating from standard docker practices makes sense here. Thanks for chiming in as always @tianon!
Activity
tianon commentedon Aug 22, 2018
Don't you have to specifically create a
SIGINThandler, as noted in https://nodejs.org/api/process.html#process_signal_events?Another alternative would be to use
--initon yourdocker runline to have Docker automatically injecttinito give the default non-pid-1 behavior ofSIGINTkilling your process if it doesn't have a registered handler.FranklinYu commentedon Aug 22, 2018
@tianon If the process is not running as root process, Node.js will catch the
SIGINTfor you. No need to write anything. I know I can write my own handler or resort totini, but it would be great if this is the default behavior.tianon commentedon Aug 22, 2018
That's not Node.js catching
SIGINT, that's the behavior of Linux around PID 1 -- if a non-1 PID doesn't capture a signal, the kernel will automatically kill the process instead. With PID 1, it will not do anything, and instead assumes the process must have a signal handler (because PID 1 is supposed to be an init system, typically).FranklinYu commentedon Aug 22, 2018
@tianon Thanks for the info. Nevertheless we can have some sort of entrypoint to catch the signal right? Or is there some policy to keep the image Dockerfile-only?
tianon commentedon Aug 22, 2018
SimenB commentedon Aug 23, 2018
Since kubernetes does not allow you to pass
--init(at least it didn't a couple of years ago, might've changed) we usedumb-initasentrypointin our images at work.I think not deviating from standard docker practices makes sense here. Thanks for chiming in as always @tianon!
@nodejs/docker happy to reopen if you disagree