首页 > 解决方案 > 损坏的 DAG:[/usr/local/airflow/dags/test.py] 没有名为“boto3”的模块。如何将 pip 安装到气流容器中?

问题描述

我有以下层次结构:

-airflow
  -dags
    -test.py
  -deployment
    -dockerfile
    -docker compose
  -scripts
  -requirements.txt

test.py文件使用scripts目录中的函数。一些脚本具有外部导入语句,例如import boto3. 我认为这就是问题所在,因为当我运行气流网络服务器时,我可以看到所有不需要这些外部包的 DAG 都已加载,但确实需要它们的 DAG 无法加载:
Broken DAG: [/usr/local/airflow/dags/test.py] No module named 'boto3'
文件docker compose看起来有些东西像这样:

version: '3'
services:
  webserver:
    build: .

我试图将这样的东西添加到我的dockerfile

FROM puckel/docker-airflow:1.10.9

WORKDIR /airflow
COPY requirements.txt /airflow
RUN pip install -U pip && pip install -r requirements.txt

但是这些软件包似乎没有安装。requirements.txt每当我启动网络服务器(docker compose up)时,如何安装我的?

标签: dockerdocker-composedockerfileairflow

解决方案


可以像...一样简单

WORKDIR /airflow
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

您可能还需要指导 Docker 构建步骤。我认为docker-compose build .或者docker-compose up --no-cache......但这是基于松散的记忆


推荐阅读