[英]docker-compose env file working in yml but not with command line arguments
I have a docker-compose file which looks like:我有一个 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"
It works as expected on running docker-compose up
.它在运行
docker-compose up
按预期docker-compose up
。 But if I remove the env_file
option from yml and pass it in CLI - docker-compose --env-file .env up
, then it doesn't pick the value of environment variables from the file.但是,如果我从 yml 中删除
env_file
选项并将其传递到 CLI - docker-compose --env-file .env up
,则它不会从文件中选择环境变量的值。
This happens because the --env-file
in CLI and env_file
in service section are not exactly the same thing.发生这种情况是因为 CLI 中的
--env-file
和 service 部分中的env_file
并不完全相同。
The former is actually a specification of the file that compose will use to substitute variables inside docker-compose.yml (the default value is .env).前者实际上是 compose 将用来替换 docker-compose.yml 中的变量的文件的规范(默认值为 .env)。
The latter is specifying the file from which the variables will be loaded and passed to the container of the service.后者指定将从中加载变量并将其传递给服务容器的文件。
And yes, it's kinda confusing.是的,这有点令人困惑。
Reference:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.