antonioACR1
antonioACR1

Reputation: 1383

Heroku "Missing required flag -a --app" error after succesfully running heroku container:push web and heroku container:release web

I have a Docker container which I'm trying to deploy as a Heroku application. My application is called

morning-bayou-58742

Previously I ran succesfully the following commands

heroku container:login

heroku create

heroku container:push web --app morning-bayou-58742

heroku container:release web --app morning-bayou-58742

The output of the latter is

Releasing images web to morning-bayou-58742... done

However when I open my web application I get the following error

Application error

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

And when I check the logs tail, I get the following

heroku logs --tail

» Error: Missing required flag: » -a, --app APP app to run command against » See more help with --help

Now what I tried to do is trying to run the Getting Started documentation from Heroku https://devcenter.heroku.com/articles/container-registry-and-runtime#getting-started which goes like this:

heroku container:login

git clone https://github.com/heroku/alpinehelloworld.git

heroku create

heroku container:push web

heroku container:release web

heroku open

and it worked fine! So I'm more confused now. Can you provide some hint about what could the problem be? Just in case, this is my Docker container structure which works fine when I run it using 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

My Docker container is called flask-heroku-bis which I run with the command

docker run -d -p 5000:5000 flask-heroku-bis

Then I get the result when I type local url calls such as http://localhost:5000/predict?sl=100.2&sw=11.7&pl=10.8&pw=3

I believe that the problem might be related to the structure of this call, however I'm not 100% sure.

Any help is appreciated!

Edit: Here's the log details:

heroku logs --tail -a morning-bayou-58742
2021-05-29T22:29:14.397676+00:00 app[api]: Release v1 created by user [email protected]
2021-05-29T22:29:14.397676+00:00 app[api]: Initial release by user [email protected]
2021-05-29T22:29:14.608281+00:00 app[api]: Enable Logplex by user [email protected]
2021-05-29T22:29:14.608281+00:00 app[api]: Release v2 created by user [email protected]
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 [email protected]
2021-05-29T23:13:14.880739+00:00 app[api]: Release v3 created by user [email protected]
2021-05-29T23:13:14.895055+00:00 app[api]: Scaled to web@1:Free by user [email protected]
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

Upvotes: 1

Views: 1410

Answers (1)

Yeong Jong Lim
Yeong Jong Lim

Reputation: 258

Since you do not have a detailed log file, it is difficult to troubleshoot here. You can try doing this first to pinpoint the exact issue:

heroku logs --tail -a morning-bayou-58742

Next, try using the command heroku open to access your deployed app as well just in case there is any typo on the url.

EDIT: Due to networking constraints within Heroku, EXPOSE in Dockerfile is not supported and CMD is required for Heroku to run the container. An example app based on Flask can be started like this (reference):

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 

Upvotes: 1

Related Questions