Have you ever seen zombie processes (marked <defunct>) in your container? Or tried to Ctrl+C a container and it didn’t stop? It’s because your entrypoint isn’t handling PID 1 responsibilities.
The PID 1 Problem
In Linux, PID 1 has special responsibilities: reaping adopted child processes and handling signals (SIGTERM, SIGINT). If your app (e.g., a heavy Java or Node app) runs as PID 1 but wasn’t designed to be an init system, it won’t handle these, leading to resource leaks.
The Solution: Tini
Use `tini` as a lightweight init system.
# Add Tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]
# Run your program under Tini
CMD ["/your/program", "-and", "-args"]
Now Tini runs as PID 1, handles signals correctly, passes them to your app, and reaps zombies. Simply adding `–init` to `docker run` also does this for local testing.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.