🧟 Key Takeaways: Docker init prevents zombie processes in containers. Essential for long-running applications.
Containers can have zombie processes. Docker init fixes this.
❌ The Problem – Zombie Processes
# ❌ Child processes become zombies # In container without init PID 1: dotnet MyApp.dll PID 10: node script.js (zombie!) PID 11: python worker.py (zombie!) PID 12: curl download (zombie!) # 🧟 Zombie processes accumulate over time # Eventually, container runs out of PID space # Container must be restarted
✅ The Solution – Docker Init
# ✅ Use docker init in Dockerfile FROM mcr.microsoft.com/dotnet/aspnet:8.0 # ✅ Install tini for proper init RUN apt-get update && apt-get install -y tini # ✅ Use tini as init ENTRYPOINT ["/usr/bin/tini", "--", "dotnet", "MyApp.dll"]
💡 Docker Compose Init
# docker-compose.yml
version: '3.8'
services:
app:
build: .
# ✅ Use init in compose
init: true
# ✅ Or use custom init
entrypoint: ["/usr/bin/tini", "--", "dotnet", "MyApp.dll"]
ports:
- "5000:80"
worker:
image: myworker:latest
init: true # ✅ Zombie protection!
environment:
- DOTNET_ENVIRONMENT=Production
💡 Pro Tip: Custom Init Script
# ✅ Custom init script
#!/bin/bash
# init.sh - Reaps zombie processes
# Start main application
dotnet MyApp.dll &
# Reaper loop
while true; do
# Reap zombie processes
wait -n || true
sleep 1
done
