使用带有conda环境的docker部署到Heroku后无法访问flask应用

时间:2019-12-12 16:00:58

标签: python docker heroku flask conda

我一直在尝试将我的Flask应用程序部署到Heroku。由于我需要通过osmnx安装一些软件包,例如conda-forge并需要python3,因此我在Dockerfile中使用heroku/miniconda映像创建了一个新的conda环境。该图像在我的机器上运行良好:

docker build -t myapp:latest .
docker run -it -p 5000:5000 myapp:latest

我可以通过http://localhost:5000访问该应用。

但是当我将其推送到heroku并尝试访问该应用程序后,我得到了application error。我哪里做错了?任何建议将不胜感激。

heroku create
heroku container:push web 
heroku container:release web

app.py

import os

from flask import Flask, render_template, request, jsonify

app = Flask(__name__)  # flask

@app.route('/')
def hello():
    print('hi')
    return jsonify({'predict': 'hi'})

if __name__ == '__main__':
    app.run(host='0.0.0.0')

Dockerfile

FROM heroku/miniconda

# Grab requirements.txt.
ADD ./webapp/requirements.txt /tmp/requirements.txt

# Install dependencies
RUN pip install -qr /tmp/requirements.txt

# Add our code
ADD ./webapp /opt/webapp/
WORKDIR /opt/webapp

RUN conda update --all

RUN conda create -n myapp python=3.8

RUN echo "source activate myapp && \ 
  conda install -y gunicorn flask && \
  gunicorn --bind 0.0.0.0:5000 wsgi" > ~/.bashrc

requirements.txt

Jinja2
Werkzeug
distribute
wsgiref

错误日志

2019-12-12T08:05:36.198329+00:00 heroku[web.1]: Starting process with command `/bin/sh -c gunicorn\ --bind\ 0.0.0.0:\52227\ wsgi`
2019-12-12T08:05:38.192281+00:00 app[web.1]: [2019-12-12 08:05:38 +0000] [3] [INFO] Starting gunicorn 20.0.4
2019-12-12T08:05:38.192904+00:00 app[web.1]: [2019-12-12 08:05:38 +0000] [3] [INFO] Listening at: http://0.0.0.0:52227 (3)
2019-12-12T08:05:38.193027+00:00 app[web.1]: [2019-12-12 08:05:38 +0000] [3] [INFO] Using worker: sync
2019-12-12T08:05:38.196937+00:00 app[web.1]: [2019-12-12 08:05:38 +0000] [5] [INFO] Booting worker with pid: 5
2019-12-12T08:05:39.875668+00:00 heroku[web.1]: State changed from starting to up
2019-12-12T08:05:57.045392+00:00 heroku[router]: at=info method=GET path="/" host=salty-spire-78220.herokuapp.com request_id=821c59f7-1d43-445f-ab32-189213d39e49 fwd="71.234.178.193" dyno=web.1 connect=0ms service=2ms status=200 bytes=172 protocol=http
2019-12-12T08:05:57.564757+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=salty-spire-78220.herokuapp.com request_id=98f73ce0-0746-4829-9d5c-21f0c14eaf74 fwd="71.234.178.193" dyno=web.1 connect=0ms service=3ms status=404 bytes=385 protocol=http
2019-12-12T08:39:51.048036+00:00 heroku[web.1]: Idling
2019-12-12T08:39:51.059265+00:00 heroku[web.1]: State changed from up to down
2019-12-12T08:39:52.029208+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-12-12T08:39:52.045411+00:00 app[web.1]: [2019-12-12 08:39:52 +0000] [3] [INFO] Handling signal: term
2019-12-12T08:39:52.046245+00:00 app[web.1]: [2019-12-12 08:39:52 +0000] [5] [INFO] Worker exiting (pid: 5)
2019-12-12T08:39:52.146325+00:00 app[web.1]: [2019-12-12 08:39:52 +0000] [3] [INFO] Shutting down: Master
2019-12-12T08:39:52.248536+00:00 heroku[web.1]: Process exited with status 0
2019-12-12T15:53:31.107555+00:00 heroku[web.1]: Unidling
2019-12-12T15:53:31.111206+00:00 heroku[web.1]: State changed from down to starting
2019-12-12T15:53:33.445428+00:00 heroku[web.1]: Starting process with command `/bin/sh -c gunicorn\ --bind\ 0.0.0.0:\49441\ wsgi`
2019-12-12T15:53:35.796555+00:00 app[web.1]: [2019-12-12 15:53:35 +0000] [3] [INFO] Starting gunicorn 20.0.4
2019-12-12T15:53:35.797246+00:00 app[web.1]: [2019-12-12 15:53:35 +0000] [3] [INFO] Listening at: http://0.0.0.0:49441 (3)
2019-12-12T15:53:35.797379+00:00 app[web.1]: [2019-12-12 15:53:35 +0000] [3] [INFO] Using worker: sync
2019-12-12T15:53:35.802113+00:00 app[web.1]: [2019-12-12 15:53:35 +0000] [5] [INFO] Booting worker with pid: 5
2019-12-12T15:53:37.249954+00:00 heroku[web.1]: State changed from starting to up
2019-12-12T15:53:39.168666+00:00 heroku[router]: at=info method=GET path="/" host=salty-spire-78220.herokuapp.com request_id=15228cf6-1e89-4a61-8588-e27bd81ec009 fwd="71.234.178.193" dyno=web.1 connect=0ms service=3ms status=200 bytes=172 protocol=http
2019-12-12T16:08:02.009401+00:00 heroku[web.1]: Restarting
2019-12-12T16:08:02.016006+00:00 heroku[web.1]: State changed from up to starting
2019-12-12T16:08:01.808927+00:00 app[api]: Release v4 created by user user@email
2019-12-12T16:08:01.808927+00:00 app[api]: Deployed web (18473777b9fd) by user user@email
2019-12-12T16:08:03.215311+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-12-12T16:08:03.233100+00:00 app[web.1]: [2019-12-12 16:08:03 +0000] [5] [INFO] Worker exiting (pid: 5)
2019-12-12T16:08:03.242295+00:00 app[web.1]: [2019-12-12 16:08:03 +0000] [3] [INFO] Handling signal: term
2019-12-12T16:08:03.346104+00:00 app[web.1]: [2019-12-12 16:08:03 +0000] [3] [INFO] Shutting down: Master
2019-12-12T16:08:03.457209+00:00 heroku[web.1]: Process exited with status 0
2019-12-12T16:08:26.328041+00:00 heroku[web.1]: Starting process with command `/bin/bash`
2019-12-12T16:08:28.907322+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-12T16:08:28.910586+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-12T16:08:28.888393+00:00 heroku[web.1]: Process exited with status 0
2019-12-12T16:08:45.746338+00:00 heroku[web.1]: Starting process with command `/bin/bash`
2019-12-12T16:08:48.097260+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-12T16:08:48.078172+00:00 heroku[web.1]: Process exited with status 0
2019-12-12T16:08:48.851256+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-spire-78220.herokuapp.com request_id=79097307-40bb-4100-b99f-1f701c1ee1fb fwd="71.234.178.193" dyno= connect= service= status=503 bytes= protocol=http

0 个答案:

没有答案