Tini is a highly minimalistic init process specifically designed for containerized
environments. In Linux systems, the init process (PID 1) plays a critical role
in managing system processes, including crucial signal handling and the reaping
of zombie processes. While traditional init systems are often overly complex
for a single-application container, the core functionalities they provide are
still essential for robust container operation.
When a container runs with only one primary child process, Tini steps in to
ensure proper process management. It effectively acts as PID 1 within the
container, addressing two common issues that arise when the main application
is not equipped to handle these init-like responsibilities:
-
Signal Handling: Tini ensures that signals sent to the container (e.g.,
SIGTERMfor graceful shutdown requests) are correctly forwarded to the main application. Without Tini, applications might not receive these critical signals, leading to abrupt termination, potential data corruption, or resource leaks instead of a controlled, graceful exit. tini -
Zombie Process Reaping: Tini correctly reaps its child processes, preventing the accumulation of "zombie" processes within the container environment. Zombie processes are defunct processes that have completed execution but still occupy a process table entry because their parent has not yet called
wait()orwaitpid()to retrieve their exit status. If the main container application is not designed to reap its own children, or if it spawns background processes that exit unexpectedly, Tini ensures these defunct processes are properly cleaned up, freeing up system resources.
Tini's design philosophy emphasizes efficiency and a small footprint. Its core logic is contained within a single C file, making it an ideal choice for lightweight container images where every byte and process matters. This simplicity contributes significantly to its reliability and ease of integration into container workflows.
FROM debian:latest RUN apt-get update RUN apt-get install -y tini ... COPY ./app /app ENTRYPOINT ["/usr/bin/tini", "/app/app", "--", "entrypoint"]