You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Airflow+dbt+Docker部署遭遇protobuf依赖冲突求助

dbt + Airflow + Docker 依赖冲突解决方案

问题背景

我是Airflow新手,在基于dbt+Airflow+Docker的项目中遇到依赖冲突:

  • 先通过pip安装了dbt-core、dbt-duckdb适配器;
  • 执行Airflow安装命令:
    pip install "apache-airflow[celery]==3.1.3" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.1.3/constraints-3.12.txt"
    
    触发依赖错误:
    dbt-common 1.36.0 requires protobuf<7.0,>=6.0, but you have protobuf 4.25.8 which is incompatible.
    dbt-adapters 1.19.0 requires protobuf<7.0,>=6.0, but you have protobuf 4.25.8 which is incompatible.
    dbt-core 1.10.15 requires protobuf<7.0,>=6.0, but you have protobuf 4.25.8 which is incompatible.
    
  • 尝试更换Python版本、强制安装指定版本protobuf时,又出现新冲突:
    opentelemetry-proto 1.27.0 requires protobuf<5.0,>=3.19, but you have protobuf 6.33.1
    
  • 试过多种Airflow和dbt版本组合、用Poetry管理依赖,均未解决。

解决方法

1. Docker容器隔离(最优解)

既然是Docker项目,直接把dbt和Airflow拆分为两个独立容器,彻底规避依赖冲突:

  • Airflow容器:使用官方稳定版镜像(如apache/airflow:2.8.4-python3.11),无需在容器内安装dbt;
  • dbt容器:基于Python镜像自定义构建,示例Dockerfile:
    FROM python:3.11-slim
    RUN pip install --no-cache-dir dbt-core==1.8.3 dbt-duckdb==1.8.1
    WORKDIR /dbt
    COPY ./dbt-project /dbt
    
  • 在Airflow中通过DockerOperator或BashOperator调用dbt容器执行任务,例如:
    from airflow.providers.docker.operators.docker import DockerOperator
    
    dbt_run_task = DockerOperator(
        task_id="dbt_run",
        image="my-dbt-image:latest",
        command="dbt run --project-dir /dbt",
        docker_url="unix://var/run/docker.sock",
        network_mode="bridge"
    )
    

2. 选择兼容的版本组合(单环境方案)

Airflow 3.x是新版本,依赖约束严格,换用Airflow 2.x稳定版搭配适配的dbt版本:

  • 推荐兼容组合:
    • Airflow:2.8.4(支持Python 3.11/3.12)
    • dbt-core:1.8.3
    • dbt-duckdb:1.8.1
  • 安装顺序:先装Airflow(带官方约束文件),再装dbt:
    # 先安装Airflow
    pip install "apache-airflow[celery]==2.8.4" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.8.4/constraints-3.11.txt"
    # 再安装dbt组件
    pip install dbt-core==1.8.3 dbt-duckdb==1.8.1
    
    该组合中,Airflow约束的protobuf版本(4.25.3)与dbt 1.8.x要求的>=3.20.3,<5.0完全兼容。

3. Poetry依赖管理优化

如果坚持用Poetry,在pyproject.toml中明确指定兼容版本范围,避免自动升级:

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
apache-airflow = {extras = ["celery"], version = "2.8.4"}
dbt-core = "1.8.3"
dbt-duckdb = "1.8.1"

执行以下命令生成兼容的锁文件:

poetry lock --no-update

内容的提问来源于stack exchange,提问作者schatz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 01:27:15