【问题标题】:Cannot call container's endpoints with Heroku deployment无法使用 Heroku 部署调用容器的端点
【发布时间】:2021-12-09 16:05:45
【问题描述】:

我最近在 Heroku 上部署了一个容器,但我似乎无法访问容器化应用程序的端点。该应用程序使用 flask_restful 并由 Gunicorn 提供服务。在本地,我使用容器的 IP 调用容器的端点没有问题,但是一旦它进入 Heroku,就没有任何作用。

这就是我在 Dockerfile 中启动 Gunicorn 的方式:

CMD gunicorn --bind 0.0.0.0:$PORT wsgi:app

而应用程序的主要是

if __name__ == '__main__':
   port = int(os.environ.get("PORT", 5000))
   app.run(debug=True, host='0.0.0.0', port=port)

在 Heroku 上,容器部署成功,Gunicorn 可以启动,但无法调用端点。这些是 Heroku 的日志:

2021-10-23T08:42:20.385661+00:00 heroku[los.1]:使用命令 /bin/sh -c gunicorn\ --bind\ 0.0.0.0:\46659\ wsgi:app 启动进程 2021-10-23T08:42:21.045713+00:00 heroku[los.1]:状态从开始变为向上 2021-10-23T08:42:21.270558+00:00 app[los.1]: [2021-10-23 08:42:21 +0000] [6] [INFO] 启动 gunicorn 20.1.0 2021-10-23T08:42:21.271015+00:00 app[los.1]: [2021-10-23 08:42:21 +0000] [6] [INFO] 收听地址:http://0.0.0.0:46659 (6) 2021-10-23T08:42:21.271099+00:00 app[los.1]: [2021-10-23 08:42:21 +0000] [6] [INFO] 使用工作者:同步 2021-10-23T08:42:21.274514+00:00 app[los.1]: [2021-10-23 08:42:21 +0000] [9] [INFO] 使用 pid 引导工作人员:9 2021-10-23T08:42:35.953189+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host= request_id=6a77117d-400b-4c17- bbe7-89163b166685 fwd="82.57.209.96" dyno= connect= service= status=503 bytes= protocol=https

我做错了吗?

提前谢谢你!

【问题讨论】:

    标签: docker heroku dockerfile gunicorn


    【解决方案1】:

    我使用了错误的进程类型。添加带有web: gunicorn wsgi:app 0.0.0.0:$PORT 的 Procfile 解决了该问题,因为 Web 进程类型是唯一能够接收外部流量的类型。

    我建议遵循this 指南。

    【讨论】:

      猜你喜欢
      • 2018-11-29
      • 2016-11-19
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多