75

I hope that this question will not be marked as primarily opinion-based, but that there is an objective answer to it.

I have read Introducing dumb-init, an init system for Docker containers, which extensively describes why and how to use dumb-init. To be honest, for someone not too experienced with how the Linux process structure works, this sounds pretty dramatic - and it feels as if you are doing things entirely wrong if you don't use dumb-init.

This is why I'm thinking about using it within my very own Docker images… what keeps me from doing this is the fact that I have not yet found an official Docker image that uses it.

  • Take mongo as an example: They call mongod directly.
  • Take postgres as an example: They call postgres directly.
  • Take node as an example: They call node directly.

If dumb-init is so important - why is apparently nobody using it? What am I missing here?

6
  • 9
    (Disclaimer: I'm the maintainer of Tini — Tini and dumb-init are both lightweight init systems for containers). Note that some official Docker images do use such an init system: Redmine, Kibana, Mongo-express, Sentry, Jenkins are good examples. As you observed, this is more often useful for full-fledged apps rather than language runtimes. Jun 6, 2016 at 7:44
  • @ThomasOrozco: Can you comment on the technical side what the difference is between tini and dumb-init? Just learning about the two and wondering with the history of tini what the itch was scratched with dumb-init. From the descriptions they seem to do the same (have not compared source-code yet).
    – hakre
    May 19, 2017 at 21:27
  • 4
    @hakre I believe the dumb-init folks were not aware of Tini when they wrote it, so it's not like they found something fundamentally wrong with Tini that they wanted to fix with dumb-init :). There are a few feature differences between the two. For example they support signal rewriting and Tini doesn't, but Tini supports subreapers and they don't. Overall, though, if you're looking for zombie reaping and that's it, either will do. May 20, 2017 at 9:09
  • @ThomasOrozco: Thanks for the explanation. This is all new to me and I still need to figure out if at all there is a problem with Zombie reaping as I have not yet found out how I can provoke it to put it to a test.
    – hakre
    May 20, 2017 at 9:28
  • 13
    Docker run now has an --init flag: Run an init inside the container that forwards signals and reaps processes. It looks like the implementation comes directly from tini May 22, 2018 at 16:28

2 Answers 2

46

Something like dumb-init or tini can be used if you have a process that spawns new processes and you don't have good signal handlers implemented to catch child signals and stop your child if your process should be stopped etc.

If your process doesn't spawn new processes (e.g. Node.js), then this may not be necessary.

I guess that MongoDB, PostgreSQL, ... which may run child processes have good signal handlers implemented. Otherwise there would have been zombie processes and someone would have filed an issue to fix this.

Only problem may be the official language images, like node, ruby, golang. They don't have dumb-init/tini in it as you normally don't need them. But it's up to the developer which may implement bad child execution code to either fix the signal handlers or use helper as PID 1.

3
  • 5
    This is not entirely true. Bash scripts for example do NOT handle and emit signals properly. Also Mongo/Postgres RELY on OS's init system to handle the zombies and handle reaping of children processes. This is just the way it works. Also, docker will soon have its own init handler (now merged in master) but until you have version which supports this, you should always have PID1 process that can reap processes. See: blog.phusion.nl/2015/01/20/…
    – Lu.nemec
    Oct 27, 2016 at 8:10
  • 1
    Many of the official images have introduced gosu, eg. mongo's entrypoint.sh as PID1 process. Dec 4, 2016 at 10:02
  • 2
    gosu README says it execs the process, which means the process will become PID1, so that's orthogonal. All gosu does is switch UID, by design (which btw is dangerous outside container use case). However having an entrypoint.sh script means the shell running that script is PID1, and could use trap to pass signals and theorethically wait --any to reap zombies — unless the script ends in exec, which it does in mongo's example. Apr 20, 2020 at 7:47
0

Nowadays, docker run has the --init option, which runs the container using tini (similar to dumb-init). Thus, you have the option to use it with any image -- if only for the practical reason of being able to use Ctrl-C to stop the process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.