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