Open rluvaton opened 2 years ago
@rluvaton When we wrote the Docker section this was evaluated and there was a reason that we did not recommend this. What is the reason? I forgot:)
One argument for using tini was about closing child-processes when the main thread dies, but very few Node app do use child processes. The other reason that you mentioned that Node won't react to signals, I'd like to verify this. If it's true, let's update the recommendation. Can you verify?
Hello there! 👋 This issue has gone silent. Eerily silent. ⏳ We currently close issues after 100 days of inactivity. It has been 90 days since the last update here. If needed, you can keep it open by replying here. Thanks for being a part of the Node.js Best Practices community! 💚
Yeah, just tested it and it doesn't get the SIGHUP
and possibly other signals as well
Had a doubt? I tested this before writing the article :-)
Had a doubt?
I tested this before writing the article :-)
Thanks for joining in!
Although there are some signals that do pass 🤔
@rluvaton When we wrote the Docker section this was evaluated and there was a reason that we did not recommend this. What is the reason? I forgot:)
One argument for using tini was about closing child-processes when the main thread dies, but very few Node app do use child processes. The other reason that you mentioned that Node won't react to signals, I'd like to verify this. If it's true, let's update the recommendation. Can you verify?
If you run the following code it'll print out positive integers on the console until you press CRTL+C, which will stop the Node process.
(function counter() {
let count = 0;
setInterval(() => {
count++;
console.log(count);
}, 1000);
})();
However, SIGINIT (CRTL+C) will be ignored if you run it in a container, which is expected behavior as described here.
FROM node:18.13-bullseye
# Uncomment the last three lines of one of the code blocks below
# to see that once you do, you'll be able to stop the Node process
# by sending SIGINT (CRTL+C).
# For Tini
# ENV TINI_VERSION v0.19.0
# ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
# RUN chmod +x /tini
# ENTRYPOINT ["/tini", "--"]
# For dumb-init
# RUN wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64
# RUN chmod +x /usr/bin/dumb-init
# ENTRYPOINT ["/usr/bin/dumb-init", "--"]
RUN echo "(function counter() { let count = 0; setInterval(() => { count++; console.log(count); }, 1000); })();" >> app.js
CMD ["node", "app.js"]
docker build -t "init-mre" .
docker run --rm "init-mre"
Hi, I know this is a very old repo / issue, however I tested my application with node 22 inside of a docker container and I was able to receive the SIGINT successfully.
{"level":30,"time":1715033483998,"pid":1,"hostname":"31a5ac8ebd91","msg":"Server listening at http://0.0.0.0:3000"} {"level":50,"time":1715033504502,"pid":1,"hostname":"31a5ac8ebd91","msg":"SIGINT received"}
Right now, we advise people to use the
CMD ["node", "server.js"]
while as stated in 10 best practices to containerize Node.js web applications with Docker by @lirantal and @goldbergyoni (and in a great talk given by Liran in NodeTLV 2021) we should usedumb-init
ortini
to start our applicationWhile we mention
tini
we don't recommend it as the best way to go and explain the danger of not using itcc @goldbergyoni