Open askhogan opened 6 years ago
Bumping it. We want to be able to do a graceful shutdown by listening to the SIGTERM
event. Currently, it's not possible to do so without a custom Dockerfile
.
The ticket has been open for almost 4 years now. Why the GCP node.js image does not implement best practices?
https://madflojo.medium.com/shutdown-signals-with-docker-entry-point-scripts-5e560f4e2d45
this article explains a great way to do that. exec to the rescue
Node.JS Foundation publishes a Docker Best Practices Guide. The guide references some recommended best practices that may not be implemented in GoogleCloudPlatform/nodejs-docker.
Question: Has Google handled the issues in the guide in some other way or is the best practice for a company to create their own node Docker image that implements these recommendations?
INIT
Node.js was not designed to run as PID 1 which leads to unexpected behaviour when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to SIGTERM (CTRL-C) and similar signals. As of Docker 1.13, you can use the --init flag to wrap your Node.js process with a lightweight init system that properly handles running as PID 1.
docker run -it --init node
In the three areasdocker run
is referenced in this repo,--init node
is not usedSIGTERM and SIGINT
When creating an image, you can bypass the package.json's start command and bake it directly into the image itself. First off this reduces the number of processes running inside of your container. Secondly it causes exit signals such as SIGTERM and SIGINT to be received by the Node.js process instead of npm swallowing them.