【问题标题】:docker-compose env file working in yml but not with command line argumentsdocker-compose env 文件在 yml 中工作,但不使用命令行参数
【发布时间】:2021-02-21 02:39:24
【问题描述】:

我有一个 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,那么它不会从文件中选择环境变量的值。

【问题讨论】:

  • 你能试试docker-compose --env-file ./.env up .envdocker-compose.yml在同一个目录吗?

标签: docker docker-compose environment-variables airflow


【解决方案1】:

这是因为 CLI 中的 --env-file 和服务部分中的 env_file 并不完全相同。

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

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

是的,这有点令人困惑。

参考:

阅读thisthis

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    相关资源
    最近更新 更多