when I deployed with Docker to Heroku my flask app it errors out with the error message:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Here is my Dockerfile:
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 5000
CMD [ "gunicorn", "--config", "gunicorn_config.py", "run:app"]
Here is the content of gunicorn_config.py:
bind = "0.0.0.0:5000"
workers = 4
threads = 4
timeout = 120
Here is script commands I use in my gitlab-ci:
script:
- docker pull $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest
- docker tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest registry.heroku.com/my-app/web
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker push registry.heroku.com/my-app/web
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app my-app
- echo "App deployed to server at https://my-app.herokuapp.com/"
Until this point everything is successful. I am able to deploy to Heroku.
But when I try to open the app it is crashed. With this command, I see the logs - Heroku logs --tail
Stopping all processes with SIGTERM
2022-04-01T06:23:03.125358+00:00 app[web.1]: [2022-04-01 06:23:03 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-04-01T06:23:03.125467+00:00 app[web.1]: [2022-04-01 06:23:03 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-04-01T06:23:03.125524+00:00 app[web.1]: [2022-04-01 06:23:03 +0000] [4] [INFO] Handling signal: term
2022-04-01T06:23:03.131769+00:00 app[web.1]: [2022-04-01 06:23:03 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2022-04-01T06:23:03.326507+00:00 app[web.1]: [2022-04-01 06:23:03 +0000] [4] [INFO] Shutting down: Master
2022-04-01T06:23:03.518148+00:00 heroku[web.1]: Process exited with status 0
2022-04-01T06:23:06.918424+00:00 heroku[web.1]: Starting process with command `gunicorn --config gunicorn_config.py run:app`
2022-04-01T06:23:07.717472+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-04-01T06:23:07.717835+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [4] [INFO] Listening at: http://0.0.0.0:5000 (4)
2022-04-01T06:23:07.717884+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [4] [INFO] Using worker: gthread
2022-04-01T06:23:07.720605+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [6] [INFO] Booting worker with pid: 6
2022-04-01T06:23:07.727693+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [7] [INFO] Booting worker with pid: 7
2022-04-01T06:23:07.776540+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [8] [INFO] Booting worker with pid: 8
2022-04-01T06:23:07.848862+00:00 app[web.1]: [2022-04-01 06:23:07 +0000] [9] [INFO] Booting worker with pid: 9
2022-04-01T06:24:07.069895+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-04-01T06:24:07.138987+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-04-01T06:24:07.316175+00:00 heroku[web.1]: Process exited with status 137
2022-04-01T06:24:07.373029+00:00 heroku[web.1]: State changed from starting to crashed
2022-04-01T06:24:07.445856+00:00 heroku[web.1]: State changed from crashed to starting
2022-04-01T06:24:13.147942+00:00 heroku[web.1]: Starting process with command `gunicorn --config gunicorn_config.py run:app`
2022-04-01T06:24:14.202704+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-04-01T06:24:14.203085+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [4] [INFO] Listening at: http://0.0.0.0:5000 (4)
2022-04-01T06:24:14.203129+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [4] [INFO] Using worker: gthread
2022-04-01T06:24:14.206105+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [6] [INFO] Booting worker with pid: 6
2022-04-01T06:24:14.239507+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [7] [INFO] Booting worker with pid: 7
2022-04-01T06:24:14.327054+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [8] [INFO] Booting worker with pid: 8
2022-04-01T06:24:14.399461+00:00 app[web.1]: [2022-04-01 06:24:14 +0000] [9] [INFO] Booting worker with pid: 9
2022-04-01T06:25:13.653641+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-04-01T06:25:13.690271+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-04-01T06:25:13.868500+00:00 heroku[web.1]: Process exited with status 137
2022-04-01T06:25:13.990309+00:00 heroku[web.1]: State changed from starting to crashed
It seems like the issue is has something to do with the PORT, but I have it set in the gunicorn_config.py file to be 5000. It even prints in the logs that it is listening at port 5000 Listening at: http://0.0.0.0:5000 (4).
Perhaps someone can see where is the issue?