【问题标题】:Flask + Gunicorn + Docker - no module named apiFlask + Gunicorn + Docker - 没有名为 api 的模块
【发布时间】:2021-11-25 21:29:59
【问题描述】:

我尝试在 docker 的 gunicorn 上运行烧瓶 项目结构: here

Docker 配置:

# syntax=docker/dockerfile:1
FROM python:3.9
WORKDIR /api

COPY ./requirements.txt ./
COPY ./api ./
RUN pip install -r ./requirements.txt

ENV FLASK_APP=.
ENV FLASK_ENV=development
ENV DATABASE_URL=postgresql://fs_integr:fs_integr@db:5432/fs_integr


# CMD [ "flask", "run", "--host=0.0.0.0", "--port=5000"]

# CMD "export FLASK_APP=/api/__init__.py"
CMD ["gunicorn", "-b", ":5000", "-e", "FLASK_APP=.", "wsgi:app"]

错误:

File "/api/wsgi.py", line 1, in <module>
api_1  |     from api import app

WSGI 文件:

from api import app

if __name__ == "__main__":
    app.run()

我知道什么是真实的,但我已经失去了几个小时(

【问题讨论】:

    标签: python docker flask gunicorn


    【解决方案1】:

    gunicorn 可以理解在哪里可以找到导入到 WSGI 文件中的 api 模块,如果我们从外部文件夹按照文件名约定运行它。所以dockerfile的CMD命令应该是这样的:

     CMD cd .. && gunicorn -b :5000 api.wsgi:app
    

    cd .. - 从 api 文件夹中退出

    &amp;&amp; - 依次执行 bash 命令

    gunicorn -b :5000 api.wsgi:app - 运行 gunicorn,绑定端口,set_path:run_flask_app

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2019-11-28
    • 2018-10-23
    • 2020-05-04
    • 2017-06-22
    相关资源
    最近更新 更多