Docker Compose Tip #26: Using restart policies effectively

Keep your services running! Restart policies ensure containers recover from crashes automatically. Available restart policies Docker Compose offers four restart options: services: # Never restart (default) dev-tool: image: debug-tools restart: "no" # Restart only on failure (non-zero exit) api: image: api:latest restart: on-failure # Always restart unless manually stopped web: image: nginx restart: unless-stopped # Always restart, even after Docker daemon restarts database: image: postgres:15 restart: always Choosing the right policy Development services: ...

February 9, 2026 · 2 min · 346 words · Guillaume Lours

Docker Compose Tip #18: Graceful shutdown with stop_grace_period

Give your containers time to clean up. Configure grace periods to ensure database connections close, transactions complete, and data saves properly. The problem By default, Docker gives containers 10 seconds to stop before forcefully killing them: services: app: image: myapp:latest # Container gets SIGTERM, then SIGKILL after 10s This can interrupt long-running operations and corrupt data. The solution Use stop_grace_period to extend shutdown time: services: worker: image: myworker:latest stop_grace_period: 2m # 2 minutes to finish current job stop_signal: SIGTERM # Signal to send first (default) Real-world examples Different services need different grace periods: ...

January 28, 2026 · 2 min · 358 words · Guillaume Lours

Docker Compose Tip #10: Using init for proper PID 1 handling

Zombie processes in your containers? Slow shutdowns? Your app shouldn’t run as PID 1. Here’s the simple fix. The problem When your app runs as PID 1, it has special responsibilities: Handle system signals (SIGTERM, SIGINT) Reap zombie processes Forward signals to child processes Most apps (especially Node.js, Python) don’t handle these well. The solution Add init: true to your service: services: app: image: node:20 init: true # Adds Tini as PID 1 command: node server.js Docker automatically injects a tiny init system (Tini) that handles PID 1 responsibilities properly. ...

January 16, 2026 · 3 min · 432 words · Guillaume Lours

Docker Compose Tip #7: Restarting single services without stopping the stack

Stop doing docker compose down && docker compose up for every code change. Docker Compose lets you restart individual services while keeping the rest running. The solution Restart just what changed: # Restart only the web service docker compose up -d web # Your database, cache, and queue keep running! This simple command saves minutes per restart. Your database keeps its data, Redis maintains its cache, message queues preserve their state. ...

January 13, 2026 · 3 min · 439 words · Guillaume Lours

Docker Compose Tip #3: Service dependencies with health checks

“Connection refused” errors? The app starts before the database is ready. Here’s the fix. What doesn’t work This only waits for the container to start, not for it to be ready: services: app: depends_on: - db # Container starts, but database isn't ready yet What actually works Add health checks: services: db: image: postgres:16 environment: POSTGRES_PASSWORD: secret healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s timeout: 5s retries: 5 start_period: 10s app: image: myapp depends_on: db: condition: service_healthy # Now it actually waits for the database Common health checks PostgreSQL: ...

January 7, 2026 · 2 min · 239 words · Guillaume Lours