How do you manage environment variables in Compose?
IntermediateConceptDocker Compose
Answer
Precedence (high to low): docker compose run -e, environment: in file, --env-file/env_file: entries, image ENV. Separately, a .env file next to the compose file feeds ${VAR} interpolation in the YAML (not the container environment automatically). Use ${VAR:?error} to fail if unset and ${VAR:-default} for defaults.
More on Docker Compose
What is Docker Compose and what problem does it solve?Beginner`docker-compose` vs `docker compose`?BeginnerShow a minimal Compose file with a web app and a database.BeginnerWhat does `depends_on` guarantee?IntermediateHow do containers in Compose reach each other?BeginnerHow does Compose choose the project name and why does it matter?Intermediate