簡體   English   中英

python package docker-compose 后未導入

[英]python package not importing after docker-compose up

當我使用docker-compose up運行我的 docker-compose.yml 文件時,它會為 boto3 package 輸出 ModuleNotFoundError。 在運行docker-compose up之前,我運行了docker build. 使用 Dockerfile 成功 pip 從 requirements.txt 文件安裝 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的錯誤 output :

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'

根據您正在使用的圖像的文檔,您可以使用 build args 安裝附加要求

webserver:
  build:
    args:
      PYTHON_DEPS: "boto3"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM