docker-compose env 文件在 yml 中工作但不使用命令行参数

标签 docker docker-compose environment-variables airflow

我有一个看起来像这样的 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)。

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

是的,这有点令人困惑。

引用:

阅读thisthis .

关于docker-compose env 文件在 yml 中工作但不使用命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64747207/

相关文章:

docker - Kubernetes 上的 VDO

docker - 运行 `minikube start` ,无法拉取 k8s.gcr 镜像,但 `docker pull` 可以

python - LEADER_NOT_AVAILABLE - docker 容器

nginx - Docker - index.html Nginx 文件共享无效

docker - docker-compose:使用env vars从同一docker-compose文件启动服务以更改容器名称

powershell - 无法读取 VSTS Online 发布变量

docker - 从图像中删除卷

python - django项目和django应用程序可以具有不同的docker镜像吗?

.net - 为什么环境变量中有不同的值?

python - Numpy 有配置文件吗?