Развертывание докера фляги на heroku get Error R10 (Boot timeout) -> Веб-процессу не удалось привязаться к $ PORT в течение 60 секунд после запуска - PullRequest
0 голосов
/ 28 июня 2019

Извините, если этот вопрос похож на многие другие.Но у меня есть очень много попыток решить эту проблему, но я не могу получить правильный код, чтобы это исправить.

Я разрабатываю флеш-приложение с использованием docker-machine и docker swarm.Когда я бегу по-местному, это работает отлично.Но когда я пытаюсь выполнить развертывание на heroku, используйте heroku.yml, я получаю сообщение об ошибке

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Я новичок в использовании heroku, так что, возможно, я что-то пропустил.Я надеюсь, что Advaced может помочь увидеть, что мне не хватает.

.
|-- 2019-06-26-17-05-08.076-VBoxSVC-5799.log
|-- app
|   |-- app.py
|   |-- Dockerfile
|   |-- requirements.txt
|   '-- static
|-- docker-compose.yml
|-- heroku.yml
|-- nginx
|   |-- Dockerfile
|   |-- nginx.conf
|   '-- smartapp.conf
'-- README.md

. / Heroku.yml

build:
  docker:
    web: app/Dockerfile
    worker: app/Dockerfile

. / App / Dockerfile

# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 8000 available to the world outside this container
#EXPOSE 8000

# Define environment variable
ENV FLASK_APP=smartapp
ENV FLASK_ENV=development

# Run run.py when the container launches
CMD ["gunicorn", "-b", "0.0.0.0", "app:app"]

. / Nginx / Dockerfile

FROM nginx
RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/
RUN rm /etc/nginx/conf.d/default.conf
COPY smartapp.conf /etc/nginx/conf.d/

. / App / app.py

from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@app.route("/")
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0:$PORT')

$ Герои бревен - хвост

2019-06-28T03:47:57.545950+00:00 heroku[web.1]: Starting process with command `gunicorn -b 0.0.0.0 app:app`
2019-06-28T03:47:59.233102+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-06-28T03:47:59.233716+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Listening at: http://0.0.0.0:8000 (4)
2019-06-28T03:47:59.233827+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Using worker: sync
2019-06-28T03:47:59.238431+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [7] [INFO] Booting worker with pid: 7
2019-06-28T03:48:57.898890+00:00 heroku[web.1]: State changed from starting to crashed
2019-06-28T03:48:57.786102+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-06-28T03:48:57.786193+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-06-28T03:48:57.883116+00:00 heroku[web.1]: Process exited with status 137
2019-06-28T03:48:58.833786+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quiet-cove-70697.herokuapp.com request_id=a0fd1087-0ac8-44c8-ac31-cb43a46a9449 fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:48:59.820240+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quiet-cove-70697.herokuapp.com request_id=cd9bce77-f818-4516-b2b0-333ab2b95eea fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:49:15.792328+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quiet-cove-70697.herokuapp.com request_id=4ba13aa2-f739-4792-9859-9ad86d9da38b fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:49:16.883549+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quiet-cove-70697.herokuapp.com request_id=1acbfe60-2023-42d5-8091-826d0156d765 fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:55:22.425339+00:00 heroku[web.1]: State changed from crashed to starting
2019-06-28T03:55:25.634810+00:00 heroku[web.1]: Starting process with command `gunicorn -b 0.0.0.0 app:app`
2019-06-28T03:55:27.616318+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-06-28T03:55:27.616885+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Listening at: http://0.0.0.0:8000 (4)
2019-06-28T03:55:27.616984+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Using worker: sync
2019-06-28T03:55:27.621084+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [7] [INFO] Booting worker with pid: 7
2019-06-28T03:56:25.725581+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-06-28T03:56:25.725672+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-06-28T03:56:25.821622+00:00 heroku[web.1]: State changed from starting to crashed
2019-06-28T03:56:25.799366+00:00 heroku[web.1]: Process exited with status 137

Спасибо

Ответы [ 2 ]

1 голос
/ 28 июня 2019

Я думаю, вам нужно передать port, а не $PORT в вашу команду запуска:

my_port = '0.0.0.0:' + str(port)
app.run(host=my_port)

вы уже присвоили переменной port правильное значение.

ивам нужно EXPOSE порт также в вашем Dockerfile

0 голосов
/ 28 июня 2019

После поиска моего решения я получил эту ссылку Добавление Gunicorn в ваше приложение . И я обновляю Dockerfile так:

# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Define environment variable
ENV FLASK_APP=smartapp
ENV FLASK_ENV=development

# Run run.py when the container launches
CMD ["gunicorn", "app:app"]

Я удаляю этот код из последней строки (см. Предыдущий код выше):

"-b", "0.0.0.0", 

А теперь моё приложение может запускаться в героку ... (o.0)

...