The Compose env_file property specifies a text file whose key/value lines are loaded into a service container as environment variables.
Use env_file in a Compose service when configuration should come from a separate text file. Compose reads each key=value line and loads the values into the container as environment variables. section 10.3
Configure it in three practical steps:
Create a text file such as ./config/logging.debug.env, with one environment variable per line. section 10.3
Reference the file under the service's env_file property; multiple components can share the same settings file instead of duplicating variables. section 10.3
How Learn Docker in a Month of Lunches, Second Edition covers it
How deep it goes
Explains the property, key=value parsing, sharing rationale, and log-based verification, but not file syntax beyond lines and equals signs.
Examples
Uses logging.debug.env and logging.information.env in todo-web development and Compose configurations.
What it assumes
Assumes familiarity with Compose services and environment variables while contrasting env_file with environment and secrets.
What you can do after
Operate/configure a Compose service with externalized environment variables and verify their effect through container logs.
How it connects
Connects environment variables with Compose services, application configuration, and secrets.
.env fileuses · A .env file is a plain-text configuration file containing environment-variable assignments that applications or tools can load at runtime.
environment variableproduces · An environment variable is a named value supplied through an operating-system or process environment and made available to programs for runtime configuration or information.
Dockerused by · Docker is a platform and ecosystem for building, distributing, and running applications in containers.
This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.