Beginner LevelDocker & Deployment
What is the Tini init process (--init) and why is it needed for zombie process reaping?
❓ Interview Prompt: Explain PID 1 responsibilities, zombie process accumulation, SIGTERM propagation, and using Tini or --init for proper signal handling.
In Linux, PID 1 (the init process) has special responsibilities that most application processes are not designed to handle:
PID 1 Responsibilities:
1
Zombie Process Reaping: When a child process exits, its parent must call
wait() to collect its exit status. If PID 1 doesn't do this, dead processes accumulate as zombie processes, consuming PID table entries until the table is full.2
Signal Forwarding: PID 1 must forward signals (SIGTERM, SIGINT) to its children — most apps don't do this by default.
The Problem with Node.js/Python as PID 1:
When you run CMD ["node", "server.js"], Node.js becomes PID 1. Node.js does NOT reap orphaned child processes — if it spawns subprocesses (e.g., 'shell commands'), those can become zombies.
Solutions:
1
`--init` flag: Docker injects Tini as PID 1 — a minimal init system that handles signal forwarding and zombie reaping.
2
Tini in Dockerfile: Explicitly install and use Tini for environments where
--init isn't available.3
`dumb-init`: A similar lightweight alternative from Yelp.
Code Implementation Example
dockerfile
# Option A: Use docker run --init flag (Tini injected automatically)
# docker run --init myapp:latest
# Option B: Install Tini explicitly in Dockerfile (recommended)
FROM node:20-alpine
# Install Tini — a minimal PID 1 init process
RUN apk add --no-cache tini
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN addgroup -S nodejs && adduser -S appuser -G nodejs
USER appuser
EXPOSE 3000
# ENTRYPOINT: Tini becomes PID 1, node is its child
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "server.js"]
# Result: Tini(PID 1) → node server.js(PID 2)
# Tini handles SIGTERM forwarding and zombie reaping💡Tini as ENTRYPOINT becomes PID 1, properly forwarding SIGTERM to Node.js and reaping zombie child processes.
🎯 Interview Key Takeaway
Use --init or install Tini as PID 1 to properly handle SIGTERM signal forwarding and zombie process reaping — critical for apps that spawn child processes.
#Docker#Tini#PID 1#Zombie Processes#SIGTERM#Beginner
Back to all Docker & Deployment Questions→