如何在现有的dockerfile中运行Flask应用程序?我如何让flask运行另一个应用程序? [英] How to run flask app in existing dockerfile? How do I have flask run another application?

查看:122
本文介绍了如何在现有的dockerfile中运行Flask应用程序?我如何让flask运行另一个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的docker文件:

I have a docker file that looks like this:

FROM python:3.7

WORKDIR /var/<some_project>

ENV PYTHONPATH "${PYTHONPATH}:/var/<some_project>"
ENV FLASK_APP "app/prometheus/__init__.py"

COPY app ./app
COPY sources ./sources
COPY *.py ./
COPY requirements.txt ./

RUN pip3 install -r requirements.txt

ENTRYPOINT ["python", "sources/passport/main.py"]

我需要在某些时候运行flask run来查看我在flask中创建的端点(在文件夹app下) 。我该怎么做才能将其添加到该dockerfile中?

I need to run flask run at some point to see my endpoint that I created in flask (under the folder app). What do I do to add this to this dockerfile?

我想我还必须让flask运行另一个 main code>应用程序,因为flask公开了另一个应用程序正在收集的数据。我如何让flask调用另一个应用程序并使其在后台运行?

I think I'm also going to have to have flask run the other main application because flask is exposing data that the other application is collecting. How do I have flask call the other application and have it run in the background?

推荐答案

我想你不想要那个enrypoint(也许您确实想要它,但是除非它要调用flask本身,否则我认为这是一个错误)。

I imagine you don't want that enrypoint (maybe you do want it, but unless it's going to call flask itself I imagine it's a mistake).

我会这样重写文件:

FROM python:3.7

WORKDIR /var/<some_project>

ENV PYTHONPATH="${PYTHONPATH}:/var/<some_project>"
ENV FLASK_APP="app/prometheus/__init__.py"

COPY requirements.txt ./

RUN pip3 install -r requirements.txt

COPY app ./app
COPY sources ./sources
COPY *.py ./

CMD flask run --host=0.0.0.0

您将需要替换 / var /< some_project> 和实际名称,您需要将 FLASK_APP 设置为绝对路径。

You're going to need to replace /var/<some_project> with the actual name and you need to set FLASK_APP to an absolute path.

由于已设置 FLASK_APP ,因此只需要运行 CMD烧瓶运行该应用程序。

Since you have FLASK_APP set you should just need CMD flask run to run the app.

我还更改了文件副本和pip安装的顺序,以帮助构建缓存。

I also changed the order of your file copies and pip install to help with build caching.

这篇关于如何在现有的dockerfile中运行Flask应用程序?我如何让flask运行另一个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆