Jan 092016
 

Docker has a PID 1 problem: On normal Unix systems his is the init process which does 3 important things (and some more):

  1. Adopt orphans
  2. Reap zombies
  3. Forward signals

There are 2 ways to start processes in a Docker container:

  1. CMD <command> <param1> <param2>…
  2. CMD [“executable”, “param1”, “param2”,…]

In the first case a shell (/bin/sh) runs your program, so PID 1 is /bin/sh. In the 2nd case your executable gets PID 1. Neither is good as neither can do what init normally does.

A fix is to run a proper init system (systemd, SysV init etc.) but that’s way more than you need. A more appropriate fix is to use a simple or dumb init. Like this: https://github.com/Yelp/dumb-init

A nice write-up from the Yelp engineering blog: http://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html

Note that this is not needed if

  • Your process runs as PID 1 and does not spawn new processes or
  • Your containers live short so that the volume of potential zombie processes won’t matter and
  • you don’t write any data so a sudden SIGTERM from Docker won’t cause issues with data consistency