Docker NameError: name 'app' is not defined Docker NameError: name 'app' is not defined flask flask

Docker NameError: name 'app' is not defined


The error you have shown in the image and the code does not seem matched. to reproduce your error is to pass app to flask object instead of __name__.

enter image description here

Here you go with HelloWorld

FROM python:alpine3.7RUN pip install flask==0.10.1COPY . /appWORKDIR /appEXPOSE 5000CMD python app.py

and app.py

from flask import Flaskapp = Flask(__name__)@app.route("/")def index():    return "Welcome to the Data Science Learner!"if __name__ == "__main__":    app.run(host="0.0.0.0", port=int("5000"), debug=True)

build

docker build -t flask-test .

run

docker run -it --rm flask-test

You can use the same with Docker compose,

docker-compose rm -f && docker-compose up --build