9.2.4.3 Config Environment Separation
A focused guide to Config Environment Separation, connecting core concepts with practical Docker and container operations.
Config environment separation refers to maintaining distinct config content for different deployment environments — development, staging, production — ensuring each environment's services receive configuration appropriate to that specific context, rather than a single, undifferentiated configuration applied everywhere.
Defining Environment-Specific Config Files
Separate files, one per environment, hold configuration appropriate to that specific context.
config/
app-config.dev.yaml
app-config.staging.yaml
app-config.prod.yaml
Selecting the Appropriate Config Through Compose Overrides
A base Compose file combined with an environment-specific override file can select the correct config source for a given deployment.
configs:
app-config:
file: ./config/app-config.dev.yaml
configs:
app-config:
file: ./config/app-config.prod.yaml
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Why This Separation Matters for Safety
Without clear separation, there's a real risk of accidentally deploying development-oriented configuration (verbose logging, relaxed security settings) to a production environment, or vice versa — a mistake with potentially serious consequences depending on what the misapplied configuration actually affects.
log_level: debug
allow_insecure_connections: true
Configuration values like these are reasonable for development but would be a meaningful security concern if mistakenly applied to production.
Validating Which Config Is Actually in Effect
Confirming exactly which configuration content a given deployment actually received helps catch a misconfiguration before it causes a problem in the wrong environment.
docker compose exec api cat /app/config.yaml
Why Config Environment Separation Matters
Deliberately maintaining and correctly selecting environment-specific configuration is an important safeguard against the kind of environment-mismatch mistakes that can otherwise lead to a development-oriented configuration setting being unintentionally and consequentially applied to production.