简体   繁体   English

Docker 中的 airflow initdb 抛出 ImportError: cannot import name 'import_string'

[英]airflow initdb in Docker throws ImportError: cannot import name 'import_string'

I am trying to dockerize airflow , my Dockerfile looks like this我正在尝试 dockerize airflow ,我的Dockerfile看起来像这样

FROM python:3.5.2

RUN mkdir -p /src/airflow
RUN mkdir -p /src/airflow/logs
RUN mkdir -p /src/airflow/plugins
WORKDIR /src
COPY . .
RUN pip install psycopg2
RUN pip install -r requirements.txt
COPY airflow.cfg /src/airflow
ENV AIRFLOW_HOME /src/airflow
ENV PYTHONPATH "${PYTHONPATH}:/src"
RUN airflow initdb
EXPOSE 8080
ENTRYPOINT ./airflow-start.sh

while my docker-compose.yml looks like this而我的docker-compose.yml看起来像这样

version: "3"
services:
  airflow:
    container_name: airflow
    network_mode: host
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8080:8080

The output of $ docker-compose build comes up like normal, every step executes and then $ docker-compose build的output正常出现,每一步执行然后

Step 12/14 : RUN airflow initdb
 ---> Running in 8b7ebe406978
[2020-04-21 10:34:21,419] {__init__.py:45} INFO - Using executor LocalExecutor
Traceback (most recent call last):
  File "/usr/local/bin/airflow", line 17, in <module>
    from airflow.bin.cli import CLIFactory
  File "/usr/local/lib/python3.5/site-packages/airflow/bin/cli.py", line 59, in <module>
    from airflow.www.app import cached_app
  File "/usr/local/lib/python3.5/site-packages/airflow/www/app.py", line 20, in <module>
    from flask_cache import Cache
  File "/usr/local/lib/python3.5/site-packages/flask_cache/__init__.py", line 24, in <module>
    from werkzeug import import_string
ImportError: cannot import name 'import_string'
ERROR: Service 'airflow' failed to build: The command '/bin/sh -c airflow initdb' returned a non-zero code: 1

postgres is running on host system. postgres在主机系统上运行。
I have tried multiple ways but this keeps on happening.我尝试了多种方法,但这种情况一直在发生。
I even tried puckel/docker-airflow image and the same error occurred.我什至尝试puckel/docker-airflow图像并发生了同样的错误。
Can someone tell me what am I doing wrong?有人可以告诉我我做错了什么吗?


Project Structure:项目结构:

root
  -airflow_dags
  -Dockerfile
  -docker-compose.yml
  -airflow-start.sh
  -airflow.cfg

In case it's relevant: airflow-start.sh如果相关: airflow-start.sh

In airflow.cfg :airflow.cfg

dags_folder = /src/airflow_dags/
sql_alchemy_conn = postgresql://airflow:airflow@localhost:5432/airflow

If possible get your code running without touching docker... run it directly on your host... of course this means your host ( your laptop or wherever you are executing your commands, could be a remote VPS debian box ) must have the same OS as your Dockerfile, I see in this case FROM python:3.5.2 is actually using debian 8如果可能的话,让您的代码在不接触 docker 的情况下运行...直接在您的主机上运行...当然这意味着您的主机(您的笔记本电脑或执行命令的任何地方,可能是远程 VPS debian 框)必须具有相同的操作系统作为您的 Dockerfile,我在这种情况下看到FROM python:3.5.2实际上是使用 debian 8

Short of doing above launch a toy container which does nothing yet executes and lets you login to it to manually run your commands to aid troubleshooting... so use following as this toy container's Dockerfile如果没有执行上述操作,则启动一个什么都不执行的玩具容器,并让您登录它以手动运行您的命令以帮助故障排除......所以使用以下作为这个玩具容器的 Dockerfile

FROM python:3.5.2

CMD ["/bin/bash"]

so now issue this所以现在发出这个

docker build --tag saadi_now .   # creates image saadi_now

now launch that image现在启动该图像

docker run -d  saadi_now  sleep infinity # launches container 

docker ps         #  lets say its container_id is b91f8cba6ed1

now login to that running container现在登录到那个正在运行的容器

docker exec -ti  b91f8cba6ed1 bash

cool so you are now inside the docker container so run the commands which were originally in the real Dockfile... this sometime makes it easier to troubleshoot很酷,所以你现在在 docker 容器内,所以运行最初在真实 Dockfile 中的命令......这有时会更容易排除故障

one by one add to this toy Dockerfile your actual commands from the real Dockerfile and redo above until you discover the underlying issues一个一个地添加到这个玩具 Dockerfile 你的实际命令来自真正的 Dockerfile 并重做上面,直到你发现潜在的问题

Most likely this is related to either a bug in airflow with the werkzeug package, or your requirements might be clobbering something.这很可能与带有 werkzeug package 的 airflow 中的错误有关,或者您的要求可能会破坏某些东西。

I recommend checking the versions of airflow, flask, and werkzueg that are used in the environment.我建议检查环境中使用的 airflow、flask 和 werkzueg 的版本。 It may be that you need to pin the version of flask or werkzueg as discussed here .您可能需要固定 flask 或 werkzueg 的版本,如此所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM