Currently, a docker app running a node server does not handle exits gracefully. If a docker stop
command executes when the application is in the middle of processing something, the application will die without waiting to finish.
Because Docker does not handle passing signals to children processes when it's run as PID1, I used a library called tini to better manage signal handling.
I also use techniques from this article to write a bash script to pass signals to the node server. We start the node server in the bash script instead of calling npm start
because npm doesn't pass signals properly.
- Use tini
- Update the
start
executable to trap signals and wait for the process to finish before killing it - Call
node
process directly instart
executable instead of proxied vianpm start
- Add signal listeners in the application JS to shut down before exiting