Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Docker Best Practices Node.JS #180

Open
askhogan opened this issue Oct 9, 2018 · 2 comments
Open

Docker Best Practices Node.JS #180

askhogan opened this issue Oct 9, 2018 · 2 comments

Comments

@askhogan
Copy link

askhogan commented Oct 9, 2018

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?

  1. 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 areas docker run is referenced in this repo, --init node is not used

  2. SIGTERM 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.

@krymen
Copy link

krymen commented Sep 20, 2022

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?

@whoisstan
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants