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

Docker Compose Tip #2: Using --env-file for different environments

Same compose.yml, different environments. Here’s the cleanest approach. Basic setup Create different env files for each environment: .env.dev DATABASE_URL=postgresql://localhost:5432/dev_db API_KEY=dev_key_12345 LOG_LEVEL=debug REPLICAS=1 .env.prod DATABASE_URL=postgresql://prod-db.example.com:5432/prod_db API_KEY=${SECURE_API_KEY} # From CI/CD secrets LOG_LEVEL=error REPLICAS=3 How to use them # Development docker compose --env-file .env.dev up # Production docker compose --env-file .env.prod up # Override specific vars API_KEY=test_key docker compose --env-file .env.dev up Layering configs You can use multiple env files: # Base + environment-specific docker compose \ --env-file .env.base \ --env-file .env.prod \ up Note: Later files override earlier ones. ...

January 6, 2026 · 1 min · 175 words · Guillaume Lours

Docker Compose Tip #1: Debug your configuration with config

When your Compose setup gets complex, docker compose config becomes your best debugging tool. Especially with profiles. The basics docker compose config This shows you the actual configuration that Docker Compose will run: Environment variables are replaced with their values Relative paths become absolute Default values are applied Multiple compose files are merged YAML anchors are resolved What you write: services: web: image: myapp:${VERSION:-latest} volumes: - ./data:/app/data environment: DATABASE_URL: ${DATABASE_URL} What docker compose config shows you: ...

January 5, 2026 · 2 min · 401 words · Guillaume Lours