【发布时间】:2021-08-17 17:53:07
【问题描述】:
我有一个 Docker 容器,我正在尝试将其部署为 Heroku 应用程序。我的应用程序被调用
morning-bayou-58742
之前我成功运行了以下命令
heroku container:login
heroku create
heroku container:push web --app morning-bayou-58742
heroku container:release web --app morning-bayou-58742
后者的输出是
将图片发布到网站morning-bayou-58742...完成
但是当我打开我的网络应用程序时,我收到以下错误
应用程序错误
应用程序发生错误,您的页面无法访问 服务。如果您是应用程序所有者,请查看您的日志以获取详细信息。 您可以从 Heroku CLI 使用命令 heroku logs 执行此操作 --尾
当我检查日志尾部时,我得到以下信息
heroku logs --tail
» 错误:缺少必需的标志:» -a, --app APP 应用程序运行 命令反对 » 使用 --help 查看更多帮助
现在我尝试从 Heroku https://devcenter.heroku.com/articles/container-registry-and-runtime#getting-started 运行入门文档,如下所示:
heroku container:login
git clone https://github.com/heroku/alpinehelloworld.git
heroku create
heroku container:push web
heroku container:release web
heroku open
而且效果很好!所以我现在更困惑了。你能提供一些关于问题可能是什么的提示吗?以防万一,这是我的 Docker 容器结构,当我使用 localhost 运行它时可以正常工作:
app.py:
#my libraries
import pickle
import numpy as np
import sys
import os
from sklearn.neighbors import KNeighborsClassifier
from flask import Flask, request
#set port
port = int(os.environ.get("PORT", 5000))
#open model back
with open('./model.pkl', 'rb') as model_pkl:
knn = pickle.load(model_pkl)
knn.n_jobs=1
#flask application
app = Flask(__name__)
#API endpoint
@app.route('/predict')
def predict_iris():
#retrieve parameters
sl = float(request.args.get('sl'))
sw = float(request.args.get('sw'))
pl = float(request.args.get('pl'))
pw = float(request.args.get('pw'))
#predict result
new_record = np.array([[sl, sw, pl, pw]])
print(new_record)
predict_result = knn.predict(new_record)[0]
#label classes
classes=['setosa', 'versicolor', 'virginica']
#encode result
if predict_result==0:
result=classes[0]
elif predict_result==1:
result=classes[1]
elif predict_result==2:
result=classes[2]
else:
print("nothing to show")
#return result
return "Prediction is: " + str(result)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=port)
Dockerfile:
FROM python:3.5.3
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT python ./app.py
Requirements.txt:
numpy==1.13
scipy==0.19.1
Flask==0.12.2
scikit-learn==0.18.1
我的 Docker 容器名为 flask-heroku-bis,我使用命令运行它
docker run -d -p 5000:5000 flask-heroku-bis
然后我在输入本地 url 调用时得到结果,例如 http://localhost:5000/predict?sl=100.2&sw=11.7&pl=10.8&pw=3
我认为问题可能与此调用的结构有关,但我不能 100% 确定。
感谢任何帮助!
编辑: 以下是日志详细信息:
heroku logs --tail -a morning-bayou-58742
2021-05-29T22:29:14.397676+00:00 app[api]: Release v1 created by user acr@ciencias.unam.mx
2021-05-29T22:29:14.397676+00:00 app[api]: Initial release by user acr@ciencias.unam.mx
2021-05-29T22:29:14.608281+00:00 app[api]: Enable Logplex by user acr@ciencias.unam.mx
2021-05-29T22:29:14.608281+00:00 app[api]: Release v2 created by user acr@ciencias.unam.mx
2021-05-29T22:48:10.986325+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=22a535c8-7762-41a2-b41a-d6d7b284dba2 fwd="187.145.160.213" dyno= connect= service= status=502 bytes= protocol=https
2021-05-29T22:48:11.914173+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=morning-bayou-58742.herokuapp.com request_id=60baae74-e461-4503-9707-b14455e5b659 fwd="187.145.160.213" dyno= connect= service= status=502 bytes= protocol=https
2021-05-29T23:13:14.880739+00:00 app[api]: Deployed web (ec731afa5e23) by user acr@ciencias.unam.mx
2021-05-29T23:13:14.880739+00:00 app[api]: Release v3 created by user acr@ciencias.unam.mx
2021-05-29T23:13:14.895055+00:00 app[api]: Scaled to web@1:Free by user acr@ciencias.unam.mx
2021-05-29T23:13:34.012193+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ ./app.py`
2021-05-29T23:13:36.661935+00:00 heroku[web.1]: Process exited with status 0
2021-05-29T23:13:36.715749+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T23:13:36.731837+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T23:14:07.678289+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ ./app.py`
2021-05-29T23:14:10.298318+00:00 heroku[web.1]: Process exited with status 0
2021-05-29T23:14:10.379011+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T23:17:25.175836+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=bfc884bc-2126-4c11-97f8-93685f427829 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T23:18:27.556876+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/predict?sl=1.2&sw=1.3&pl=2.2&pw=2.5" host=morning-bayou-58742.herokuapp.com request_id=ee53e591-8073-43a0-b11f-96f7e0c45d3f fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T23:27:11.115330+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=7546a2d3-303f-41f0-b088-8e91efa73056 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T23:40:18.663684+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T23:40:38.521811+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ ./app.py`
2021-05-29T23:40:42.122447+00:00 heroku[web.1]: Process exited with status 0
2021-05-29T23:40:42.188076+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T23:48:59.865089+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="//predict?sl=100.2&sw=11.7&pl=10.8&pw=3" host=morning-bayou-58742.herokuapp.com request_id=10154798-1a4a-40ca-998a-f7ee4d246f01 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:41:44.486049+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="//predict?sl=100.2&sw=11.7&pl=10.8&pw=3" host=morning-bayou-58742.herokuapp.com request_id=b9144b62-50a3-47cb-9c68-c603325d3fd5 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:41:52.067158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/predict?sl=100.2&sw=11.7&pl=10.8&pw=3" host=morning-bayou-58742.herokuapp.com request_id=81eb9141-ac91-4d0d-a5ed-effcbd38a5c3 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:41:57.056831+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/predict?sl=10.2&sw=11.7&pl=10.8&pw=3" host=morning-bayou-58742.herokuapp.com request_id=44b3cb17-9d78-49cf-85d6-1cc3c322faf3 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:42:06.449665+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=f06a1b78-869e-49a4-8d49-35c9c818d58d fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:49:28.827777+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=4554ee2a-535d-4065-b918-c79b3fa3842d fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:49:37.654869+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-bayou-58742.herokuapp.com request_id=7aa83238-3fc4-4008-869a-1c5e63800a94 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T00:50:02.630469+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/predict?sl=100.2&sw=11.7&pl=10.8&pw=3" host=morning-bayou-58742.herokuapp.com request_id=155dad59-5ed6-4566-8256-dabe4f844575 fwd="187.145.160.213" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T01:06:53.316983+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-30T01:07:14.003209+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ ./app.py`
2021-05-30T01:07:17.213751+00:00 heroku[web.1]: Process exited with status 0
2021-05-30T01:07:17.284112+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-30T02:50:08.542836+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-30T02:50:28.877273+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ ./app.py`
2021-05-30T02:50:31.667687+00:00 heroku[web.1]: Process exited with status 0
2021-05-30T02:50:31.734689+00:00 heroku[web.1]: State changed from starting to crashed
【问题讨论】: