docker编写的env文件使用yml,但不使用命令行参数



我有一个docker compose文件,看起来像:

version: '3.8'
services:
scheduler:
image: apache/airflow
command: scheduler
restart: on-failure
env_file:
- .env
volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
webserver:
image: apache/airflow
entrypoint: ./scripts/entrypoint.sh
restart: on-failure
depends_on:
- scheduler
env_file:
- .env
volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./scripts:/opt/airflow/scripts
ports:
- "8080:8080"

它在运行docker-compose up时按预期工作。但是,如果我从yml中删除env_file选项并在CLI-docker-compose --env-file .env up中传递它,那么它就不会从文件中选择环境变量的值。

之所以会发生这种情况,是因为CLI中的--env-file和服务部分中的env_file并不完全相同。

前者实际上是compose将用于替换docker-compose.yml中的变量的文件规范(默认值为.env(

后者指定将从中加载变量并将其传递到服务容器的文件。

是的,这有点令人困惑。

参考:

读这个和这个。

最新更新