Node Docker and SIGTERM

Published on:

I am not sure why but outside of docker your node app will exit immediately
on SIGTERM even if you don't have a SIGTERM handler. But when you run your
app in a docker it does not immediately quit on SIGTERM. It takes 10
seconds and then docker has to SIGKILL it.

This simple app without the SIGTERM handler will need to be killed by Docker. But outside of Docker it exits immediately.

Full example project here: https://github.com/johndstein/docker-syslog-loglove

#!/usr/bin/env node

var log = new(require('loglove'))().log(__filename.substring(process.cwd().length));

log.info('we are logging out something here.');

process.on('SIGTERM', function() {
  console.log('SIGTERM');
  process.exit(0);
});

setInterval(function() {
  log.info('we are logging out something here.');
}, 5000);