Loads container environment variables from one or more files.
Section: Environment Variables and Env Files
Load variables from env file
yaml
yaml
services:
api:
image: myapi:latest
env_file:
- .env
- .env.localExplanation
Good for keeping service config out of the main YAML.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Environment Variables and Env Files
Pass env file at runtime
Uses a specific env file when rendering the Compose project.
Environment as key/value map
Provide container environment values inline in YAML.
Environment as list
Alternative environment syntax using `KEY=value` entries.
Interpolate variables into compose file
Uses shell-style variable interpolation inside the Compose file.
Minimal web + db stack
Simple two-service stack with port publishing and environment variables.
Define optional profiles
Marks a service as optional unless its profile is enabled.