Interview Prep/Docker/Docker Compose

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.

All Docker questions Roadmap: Docker & containers

More on Docker Compose