Docker Compose Tip #50: GPU support with deploy.resources

Running ML models, video processing, or any GPU-accelerated workload? Compose lets you reserve GPU devices for specific services. Basic GPU access Give a service access to all available GPUs: services: ml-training: image: pytorch/pytorch deploy: resources: reservations: devices: - driver: nvidia count: all capabilities: [gpu] Limiting GPU count Reserve a specific number of GPUs instead of all: services: inference: image: mymodel:latest deploy: resources: reservations: devices: - driver: nvidia count: 1 capabilities: [gpu] Selecting specific GPUs by ID Target specific GPU devices when you have multiple: ...

April 8, 2026 · 2 min · 296 words · Guillaume Lours

Docker Compose Tip #44: Signal handling in containers

When you run docker compose down or docker compose stop, Compose sends a signal to your containers. Understanding which signal is sent and how your application handles it is key to graceful shutdowns. Default behavior By default, Compose sends SIGTERM to the main process (PID 1), waits 10 seconds, then sends SIGKILL: services: app: image: myapp # Default: SIGTERM, 10s grace period, then SIGKILL Changing the stop signal Some applications expect a different signal. Nginx, for example, uses SIGQUIT for graceful shutdown: ...

March 25, 2026 · 2 min · 386 words · Guillaume Lours

Docker Compose Tip #41: Container lifecycle hooks

Docker Compose supports lifecycle hooks that let you run commands at specific points in a container’s lifecycle, right after it starts and just before it stops. post_start hook Run a command inside the container right after it starts — perfect for initialization tasks like database migrations: services: api: image: myapp-api post_start: - command: /app/migrate.sh depends_on: postgres: condition: service_healthy Or warming up caches so the service is ready to handle traffic: ...

March 18, 2026 · 2 min · 306 words · Guillaume Lours

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