advancedTop 100 Interview Questions

What's the purpose of `environment:` vs `env_file:` in a compose.yaml?

Both ultimately set environment variables inside the container; `environment:` lists them inline in the compose file, while `env_file:` loads them from an external file. Neither is a secrets mechanism — both result in variables visible via `docker inspect` or inside the container's environment.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why is scaling a stateful service (like a database) fundamentally different from scaling a stateless API service?← Back to all Docker questions