goldbergyoni / goldbergyoni/nodebestpractices
Change bootstrap with node in Docker to run with dumb-init / tini
- Dominant language
- Dockerfile
- Stars
- 106k
- Forks
- 10.7k
- PR merge metrics
- No merged PRs in 30d
Description
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](https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/) by @lirantal and @goldbergyoni (and in a great talk given by Liran in NodeTLV 2021) we should use `dumb-init` or `tini` to start our application
> To quote the Node.js Docker working group recommendation on this: “Node.js was not designed to run as PID 1 which leads to unexpected behavior when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to SIGINT (CTRL-C) and similar signals”.
>
> The way to go about it then is to use a tool that will act like an init process, in that it is invoked with PID 1, then spawns our Node.js application as another process whilst ensuring that all signals are proxied to that Node.js process. If possible, we’d like a small as possible tooling footprint for doing so to not risk having security vulnerabilities added to our container image.
>
> From (the same article mentioned above) [Why you should use a tool that will act like an init process](https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/#:~:text=To%20quote%20the,our%20container%20image.)
While we mention `tini` we don't recommend it as the best way to go and explain the danger of not using it
cc @goldbergyoni
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.