Docker Community Forums

Share and learn in the Docker community.

Problem with flask running

I put this code (python) in my container:

root@e9bcddeb9491:/# cat > /opt/
import os
from flask import Flask
app = Flask(__name__)

def main():
    return "Welcome!"

@app.route('/how are you')
def hello():
    return 'I am good, how about you?'

if __name__ == "__main__":"", port=8080, Debug=True)

and then I ran flask run --host=

And I got this erorr:

root@e9bcddeb9491:/# flask run --host=
 * Serving Flask app '' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

**Error: Could not import 'app'.**

If you know what the problem is- It will help me a lot,
thank you!

Your code seems working, I tried. how did you installed flask and python? Which Python version are you using?

I would also check if you use the same as you shared here, because I don’t understand why Python wants to import “app”.

This is my working Dockerfile

FROM python:3.8

RUN python3 -m pip install flask
RUN mkdir /app
COPY /app
CMD ["flask", "run", "--host="]

Thank you very much!