This way, the Node process itself will run as PID 1 of the container (instead of just being a child process of NPM).
The same can be found in other collections of best practices such as [2].
What I do is a bit more complex: an entrypoint.sh which ends up running
exec node main.js "$*"
Docs then tell users to use "docker run --init"; this flag will tell Docker to use the Tini minimal init system as PID 1, which handles system SIGnals appropriately.[0]: https://github.com/nodejs/docker-node/blob/main/docs/BestPra...
[1]: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
[2]: https://dev.to/nodepractices/docker-best-practices-with-node...
Edit: corrected the part about using --init for proper handling of signals.
Edit: Consequently this should make the container logs a bit more useful, beyond better signal handling/respect
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "/path/to/main/process.js"]
[0]: https://github.com/krallin/tiniedit: formatting, sorry.
If you use Kubernetes then you have to add tini for now (https://github.com/kubernetes/kubernetes/issues/84210)