gitmyhub

dumb-init

Python ★ 7.3k updated 2mo ago

A minimal init system for Linux containers

dumb-init is a tiny static binary from Yelp that runs as the first process inside a Docker container, forwarding shutdown signals to your app and cleaning up zombie processes so containers shut down cleanly.

CPythonsetup: easycomplexity 2/5

dumb-init is a tiny program designed to run as the first process inside a Linux container, such as a Docker container. It solves two specific problems that come up when you run an application directly as the first process in a container without any traditional init system in place.

The first problem is signal handling. When you stop a Docker container, the operating system sends a signal to the container's first process asking it to shut down. If your application is not specifically written to handle that signal, nothing happens and the container hangs. dumb-init sits between the operating system and your application, catches those signals, and forwards them to your process in a way that causes normal default behavior, such as actually stopping when asked.

The second problem is zombie processes. When a subprocess finishes but its parent does not properly acknowledge that it finished, the finished process lingers in a special state called a zombie. In a normal operating system, the init process (the first process, which is always running) handles these automatically. In a container without an init process, zombies can accumulate. dumb-init takes on that cleanup responsibility.

Using it is straightforward: instead of running your application directly, you prefix it with dumb-init. For example, instead of running your web server directly, you run dumb-init followed by your web server command. dumb-init starts your process as its child and handles all the signal and zombie management from that point on.

dumb-init also supports signal rewriting, which lets you translate one type of stop signal into another before forwarding it to your application. This is useful when a container orchestration system always sends a particular signal but your application expects a different one to start a clean shutdown.

The binary is statically linked, meaning it has no external dependencies and can be dropped into any Linux container image directly. Installation options include a package manager, a downloaded binary, or a Python package via pip. Yelp originally created and open-sourced this tool.

Where it fits