Docker中的Blask应用没有加载更新的HTML

发布于 2025-01-29 06:06:18 字数 732 浏览 2 评论 0原文

我已经将烧瓶应用程序包装到了Docker图像中。该应用程序根据后响应将新内容添加到现有的HTML(在烧瓶应用程序中渲染)。虽然HTML的新内容正确显示在我的本地上,但从Docker运行的应用程序仍显示旧内容。 我已经进行了检查,以确认已成功发送发布请求,并确认正在添加新内容。重新启动后,Docker容器在重新启动Docker容器时正确显示HTML的内容。

我怀疑该容器正在缓存HTML文件。构建Docker时是否有设置以不缓存HTML的内容?  

#start by pulling the python image
FROM python:3.6

ENV PYTHONUNBUFFERED True

#copy the requirements file into the image
COPY ./requirements.txt/app/requirements.txt

#switch working directory
WORKDIR /app

#install the dependencies and packages in the requirements file
RUN pip install -r requirements.txt

#copy every content from the local file to the image
COPY ./app

CMD exec gunicorn --bind 0.0.0.0:8000 --workers 1 --threads 8 --timeout 0 driver:app

I have containerized my flask app into a docker image. The application adds new content to an existing html (rendered in flask app) based on a POST response. While the new contents of html are displayed correctly on my local, app ran from docker still displays the old content.  I have put in checks to confirm that POST request is successfully sent as well as to confirm that new contents are being added. Upon restart though, the docker container displays the contents of html correctly upon restarting the docker container.

I am suspecting that the container is caching html files. Is there a setting while building the docker to not cache the contents of html?  

#start by pulling the python image
FROM python:3.6

ENV PYTHONUNBUFFERED True

#copy the requirements file into the image
COPY ./requirements.txt/app/requirements.txt

#switch working directory
WORKDIR /app

#install the dependencies and packages in the requirements file
RUN pip install -r requirements.txt

#copy every content from the local file to the image
COPY ./app

CMD exec gunicorn --bind 0.0.0.0:8000 --workers 1 --threads 8 --timeout 0 driver:app

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中二柚 2025-02-05 06:06:18

在下面添加代码

@app.before_request
def before_request():
    app.jinja_env.cache = {}

并在main()中调用它,如下面解决了问题

app.before_request(before_request)

Adding the code below

@app.before_request
def before_request():
    app.jinja_env.cache = {}

and calling it inside main() like below solves the issue

app.before_request(before_request)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文