【问题标题】:python package not importing after docker-compose updocker-compose up后python包不导入
【发布时间】:2020-05-10 23:04:34
【问题描述】:

当我使用docker-compose up 运行我的 docker-compose.yml 文件时,它会为 boto3 包输出一个 ModuleNotFoundError。在运行 docker-compose up 之前,我使用 Dockerfile 运行了 docker build .,该 Dockerfile 成功地从 requirements.txt 文件中 pip 安装了 boto3。到目前为止,我只尝试过退出并重新启动 Docker。

这是 Dockerfile:

WORKDIR /usr/local/airflow/
COPY requirements.txt ./
RUN pip install --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

这是 docker-compose.yml 文件:

version: '3.7'
services:
    postgres:
        image: postgres:9.6
        environment:
            - POSTGRES_USER=airflow
            - POSTGRES_PASSWORD=airflow
            - POSTGRES_DB=airflow
        logging:
            options:
                max-size: 10m
                max-file: "3"
    webserver:
        image: puckel/docker-airflow:1.10.9
        restart: always
        depends_on:
            - postgres
        environment:
            - LOAD_EX=n
            - EXECUTOR=Local
        logging:
            options:
                max-size: 10m
                max-file: "3"
        volumes:
            - ./dags:/usr/local/airflow/dags
            - ./plugins:/usr/local/airflow/plugins
        ports:
            - "8080:8080"
        command: webserver
        healthcheck:
            test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
            interval: 30s
            timeout: 30s
            retries: 3

这是docker-compose up 的错误输出:

Traceback (most recent call last):
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/models/dagbag.py", line 243, in process_file
webserver_1  |     m = imp.load_source(mod_name, filepath)
webserver_1  |   File "/usr/local/lib/python3.7/imp.py", line 171, in load_source
webserver_1  |     module = _load(spec)
webserver_1  |   File "<frozen importlib._bootstrap>", line 696, in _load
webserver_1  |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
webserver_1  |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
webserver_1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
webserver_1  |   File "/usr/local/airflow/dags/stage_fact_dag.py", line 1, in <module>
webserver_1  |     from operators import (CreatedTableOperator, StageToRedshiftOperator, DataQualityOperator)
webserver_1  |   File "/usr/local/airflow/plugins/operators/__init__.py", line 1, in <module>
webserver_1  |     from operators.stage_redshift import StageToRedshiftOperator
webserver_1  |   File "/usr/local/airflow/plugins/operators/stage_redshift.py", line 1, in <module>
webserver_1  |     from airflow.contrib.hooks.aws_hook import AwsHook
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/contrib/hooks/aws_hook.py", line 26, in <module>
webserver_1  |     import boto3
webserver_1  | ModuleNotFoundError: No module named 'boto3'

【问题讨论】:

  • 如何在 docker-compose 中引用 DockerFile?
  • 我没有在 docker-compose 中引用 DockerFile。我该怎么办?

标签: python docker docker-compose dockerfile airflow


【解决方案1】:

According to the docs for the image you are using,您可以使用 build args 安装附加要求

webserver:
  build:
    args:
      PYTHON_DEPS: "boto3"

【讨论】:

  • 我添加了你的 sn-p 并得到了错误:ERROR: The Compose file is invalid because: Service webserver has neither an image nor a build context specified. At least one must be provided.
猜你喜欢
  • 2018-12-18
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
  • 2019-07-22
  • 1970-01-01
  • 2021-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多