首页 > 解决方案 > Docker + Django + PostgreSQL + Heroku = 无法在 60 秒内绑定到 $PORT

问题描述

所以我正在构建一个 Dockerized Django 项目,我想将它部署到 Heroku,但我遇到了很多问题。我的问题与这篇文章完全相同: Docker + Django + Postgres Add-on + Heroku

除了我不能使用 CMD python3 manage.py runserver 0.0.0.0:$PORT 因为我收到一个无效的端口对错误。

我只是在跑步

heroku container:push web
heroku container:release web
heroku open

转到该站点后,它会一直加载,直到它说发生了错误。我的日志显示以下内容:

 System check identified no issues (0 silenced).
2019-05-03T11:38:47.708761+00:00 app[web.1]: May 03, 2019 - 11:38:47
2019-05-03T11:38:47.709011+00:00 app[web.1]: Django version 2.2.1, using settings 'loan_app.settings.heroku'
2019-05-03T11:38:47.709012+00:00 app[web.1]: Starting development server at http://0.0.0.0:8000/
2019-05-03T11:38:47.709014+00:00 app[web.1]: Quit the server with CONTROL-C.
2019-05-03T11:38:55.505334+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=albmej-loan-application.herokuapp.com request_id=9037f839-8421-46f2-943a-599ec3cc6cb6 fwd="129.161.215.240" dyno= connect= service= status=503 bytes= protocol=https
2019-05-03T11:39:45.091840+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-03T11:39:45.012262+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-05-03T11:39:45.012440+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-05-03T11:39:45.082756+00:00 heroku[web.1]: Process exited with status 137

该应用程序通过虚拟环境在本地运行并使用 Docker,但不在 Heroku 上。不知道还有什么可以尝试的。您可以在以下位置找到我的代码:https ://github.com/AlbMej/Online-Loan-Application

也许我的 Dockerfile 或 docker-compose.yml 中有一些明显的问题

标签: djangodockerherokudocker-composedockerfile

解决方案


答案不正确。

如果将容器与 Dockerfile 一起使用,则不需要任何 Profile。

只需使用 $PORT 变量让 heroku 确定要使用的端口。

https://help.heroku.com/PPBPA231/how-do-i-use-the-port-environment-variable-in-container-based-apps


推荐阅读