Python “希罗库”;缺少所需的标志-a--app";成功运行heroku容器:推送web和heroku容器:释放web后出错

Python “希罗库”;缺少所需的标志-a--app";成功运行heroku容器:推送web和heroku容器:释放web后出错,python,docker,heroku,Python,Docker,Heroku,我有一个Docker容器,我正试图将其部署为Heroku应用程序。我的申请被称为 morning-bayou-58742 之前,我成功地运行了以下命令 heroku容器:登录 heroku创建 heroku容器:推送web--app morning-bayou-58742 heroku容器:发布web——应用程序morning-bayou-58742 后者的产出是 将图像发布到morning-bayou-58742网站。。。完成 然而,当我打开我的web应用程序时,我得到了以下错误 应用程序错

我有一个Docker容器,我正试图将其部署为Heroku应用程序。我的申请被称为

morning-bayou-58742
之前,我成功地运行了以下命令

heroku容器:登录

heroku创建

heroku容器:推送web--app morning-bayou-58742

heroku容器:发布web——应用程序morning-bayou-58742

后者的产出是

将图像发布到morning-bayou-58742网站。。。完成

然而,当我打开我的web应用程序时,我得到了以下错误

应用程序错误

应用程序中出现错误,无法访问您的页面 服务。如果您是应用程序所有者,请查看日志以了解详细信息。 您可以使用命令Heroku logs从Heroku CLI执行此操作 --尾巴

当我检查日志尾部时,我得到以下信息

heroku日志--tail

»错误:缺少必需的标志:»-a,--app以运行 命令反对»请参阅有关--help的更多帮助

现在我尝试运行Heroku的入门文档,如下所示:

heroku容器:登录

git克隆https://github.com/heroku/alpinehelloworld.git

heroku创建

heroku容器:推送web

heroku容器:发布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

然后,当我键入本地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

由于您没有详细的日志文件,因此很难在此处进行故障排除。您可以先尝试这样做,以查明确切的问题:

heroku logs --tail -a morning-bayou-58742
接下来,尝试使用命令
heroku open
访问您部署的应用程序,以防url上出现任何输入错误

编辑: 由于Heroku内部的网络限制,Dockerfile中的
EXPOSE
不受支持,Heroku运行容器需要
CMD
。基于Flask的示例应用程序可以这样启动():


谢谢你的回答!我已经在问题的末尾包含了日志详细信息(很抱歉之前没有包含它们)。我使用heroku open命令看到了相同的结果,这意味着url上没有输入错误。任何额外的帮助都将不胜感激!根据示例,您不应该使用EXPOSE,而应该使用环境变量
$PORT
进行绑定。这是由于Heroku内部的网络限制。事实上,我通过删除EXPOSE 5000和ENTRYPOINT部分并添加命令CMD[“python”,“/app.py”]解决了这个问题。非常感谢。
FROM python:3.5.3

COPY . /app

WORKDIR /app

RUN pip install -r requirements.txt

# Expose is NOT supported by Heroku
# EXPOSE 5000

# Run the app.  CMD is required to run on Heroku
# $PORT is set by Heroku            
CMD gunicorn --bind 0.0.0.0:$PORT wsgi