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.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full DevOps Mastery library.

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

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