docker-compose教程:env_file从文件中获取环境变量

env_file用法

从文件中获取环境变量,可以为单独的文件路径或列表。
如果通过 docker-compose -f FILE 方式来指定 Compose 模板文件,则 env_file 中变量的路径会基于模板文件路径。
如果有变量名称与 environment 指令冲突,则按照惯例,以后者为准。

env_file: .env

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

环境变量文件中每一行必须符合格式,支持 # 开头的注释行。

# common.env: Set development environment
PROG_ENV=development

会自动读取.env

在这里插入图片描述

environment跟env_file的作用范围

environment跟env_file的作用范围是有差别的,就单纯从环境变量来看,environment的优先级更高,从占位符替换来看,却只能使用env_file(.env)


links:

猜你喜欢

转载自blog.csdn.net/a772304419/article/details/132913403