Environment Variables and Configuration
LEVEL 0
The Problem
Your application needs configuration:
- Database connection strings
- API keys
- Feature flags
- Passwords
Hardcoding these in your Dockerfile or source code is a bad idea. You can’t change them without rebuilding. You can’t have different values for development vs. production. And you definitely shouldn’t commit passwords to git.
Environment variables solve this.
But managing environment variables for multiple services in Compose introduces new questions:
- Where do you define them?
- How do you keep secrets out of git?
- How do you share common values across services?
- How do you handle different environments (dev, staging, prod)?