首页 > 解决方案 > 当我运行我的应用程序的“docker run”时,它运行烧瓶。为什么我不能在 localhost 上访问它,但我可以在 127.0.0.1 上访问它?

问题描述

在运行我的 docker run 命令来运行我的启动烧瓶应用程序的 python 脚本后,我在我的日志中看到了这一点:

 2019-08-02 18:29:27,519 - <some_file - INFO - Opening connection for subscription [account]
 * Serving Flask app "webserver.app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
2019-08-02 18:29:27,520 - sources.passport.listener - INFO - Opening connection for subscription [lead]
2019-08-02 18:29:27,523 - sources.passport.listener - INFO - Opening connection for subscription [opportunity]
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 ...<more logs>

当我点击时,http://127.0.0.1:5000/metrics我看到我的页面是一个烧瓶页面,但是当我点击时http://localhost:5000/metrics我没有。从概念上讲,发生了什么?我以为他们会一样?

这是我运行的 docker 命令:

docker run -e ENV='dev' -e token=foo:bar <application>

而且我什至没有使用-p标志,所以这是怎么回事?我有点失落。如何在没有端口转发的情况下访问 docker flask url?

我的代码是这样的:

def start_server():
    app.debug = False
    app.run()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()

    threading.Thread(target=start_server).start()

    for subscription in SUBSCRIPTION_TYPES:
        loop.create_task(subscribe(subscription))
    loop.run_forever()

标签: dockerflask

解决方案


推荐阅读