且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Docker容器中运行Python Flask

更新时间:2022-05-02 22:21:52

尝试 app.run(host ='0.0.0.0')

默认情况下,Flask服务器仅可从本地主机访问。在您的情况下,容器是本地主机,并且您的请求是从容器外部发出的。 host ='0.0.0.0'参数使服务器可以从外部IP访问。 Flask文档中有详细描述。

By default, Flask server is only accessible from the localhost. In your case, the container is the localhost, and your requests are originating from outside the container. host='0.0.0.0' parameter makes the server accessible from external IPs. It's described in Flask documentation in detail.