docker-compose tutorial: env_file gets environment variables from file

env_file usage

Get environment variables from a file, which can be a separate file path or a list.
If docker-compose -f FILEthe Compose template file is specified via the method, the path to the variable in env_file will be based on the template file path.
If a variable name environmentconflicts with a directive, by convention the latter takes precedence.

env_file: .env

env_file:
  - ./common.env
  - ./apps/web.env
  - /opt/secrets.env

Each line in the environment variable file must conform to the format, and comment lines starting with # are supported.

# common.env: Set development environment
PROG_ENV=development

.env will be read automatically

Insert image description here

The scope of environment and env_file

There is a difference in the scope of environment and env_file. From the perspective of environment variables, environment has a higher priority. From the perspective of placeholder replacement, only env_file(.env) can be used.


links:

Guess you like

Origin blog.csdn.net/a772304419/article/details/132913403