gitmyhub

tini

C ★ 11k updated 1y ago

A tiny but valid `init` for containers

Tini is a tiny init process for Docker containers that cleans up zombie processes and ensures Docker stop signals actually reach your running application, with near-zero overhead.

Csetup: easycomplexity 2/5

Tini is a very small program designed to run as the first process inside a container. When you start a container, something needs to act as the "init" process: the parent of all other processes, responsible for basic housekeeping. Tini fills that role with almost no overhead.

The two main jobs Tini handles are reaping zombie processes and forwarding signals. Zombie processes are programs that have finished running but whose exit status was never collected by a parent process. If they pile up over time they consume process ID slots, which can eventually make the whole system unresponsive. Tini automatically collects those exit statuses so zombies never accumulate. Signal forwarding means that when you tell Docker to stop a container, the stop command actually reaches your running program rather than getting lost.

If you are using Docker version 1.13 or newer, Tini is already bundled with Docker. You can activate it simply by adding the flag --init when running a container, with no installation required. For older setups or images where you want it explicitly present, you can download the Tini binary, add it to your container, and set it as the entrypoint so your actual program runs underneath it. Packages are also available for Alpine Linux, Debian, NixOS, and Arch Linux.

Tini has a handful of optional settings. You can enable extra log output with a verbosity flag. If Tini cannot run as the first process (process ID 1), a subreaper mode tells the operating system to reparent orphaned processes to Tini anyway. A separate option lets Tini kill an entire process group when it receives a signal, which is useful when a parent process does not pass signals down to its children on its own. There is also a flag to remap specific exit codes, which helps with programs that return unusual codes on a normal shutdown.

The project is written in C, ships signed and checksum-verified binaries for x86-64, 32-bit, and ARM platforms, and has no runtime dependencies beyond the standard C library.

Where it fits