title: Dockerize Flask: Error: While importing 'app', an ImportError was raised
body: <p>I am trying to dockerize my Flask API. As soon as I try to start my image I receive the message:</p>
  <pre><code>* 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: python -m flask run [OPTIONS]
  Try 'python -m flask run --help' for help.
  
  Error: While importing 'app', an ImportError was raised.
  </code></pre>
  <p>If I am starting the Flask App with my terminal <code>python -m flask run</code>  everything works like intended.
  And right now I am stuck on this problem.</p>
  <p>Here is my Code:</p>
  <pre><code>from flask import Flask
  from bson import json_util
  from flask_pymongo import PyMongo
  from flask_cors import CORS
  import json
  
  app = Flask(__name__)
  app.config[&quot;MONGO_URI&quot;] = &quot;mongodb://194.163.147.192:27017/test&quot;
  CORS(app)
  mongo = PyMongo(app)
  
  
  def parse_json(data):
      return json.loads(json_util.dumps(data))
  
  
  @app.route('/')
  def home():
      return 'Hello'
  
  
  @app.route('/residential', methods=['GET'])
  def find_residential():  # put application's code here
      test = mongo.db.acs.find_one({&quot;name&quot;: &quot;Residential&quot;})
      response = Flask.jsonify(parse_json(test))
      response.headers.add('Access-Control-Allow-Origin', '*')
      return response
  
  
  @app.route('/commercial', methods=['GET'])
  def find_commercial():  # put application's code here
      test = mongo.db.acs.find_one({&quot;name&quot;: &quot;Commercial&quot;})
      response = Flask.jsonify(parse_json(test))
      response.headers.add('Access-Control-Allow-Origin', '*')
      return response
  
  
  @app.route('/healthcare', methods=['GET'])
  def find_health_care():  # put application's code here
      test = mongo.db.acs.find_one({&quot;name&quot;: &quot;Health Care&quot;})
      response = Flask.jsonify(parse_json(test))
      response.headers.add('Access-Control-Allow-Origin', '*')
      return response
  
  
  @app.route('/germany', methods=['GET'])
  def find_germany():
      test = mongo.db.germanies.find_one()
      response = Flask.jsonify(parse_json(test))
      response.headers.add('Access-Control-Allow-Origin', '*')
      return response
  
  
  if __name__ == '__main__':
      app.debug = False
      app.run()
  </code></pre>
  <p>My requirements.txt looks like this</p>
  <pre><code>bson==0.5.10
  click==8.0.3
  colorama==0.4.4
  Flask==2.0.2
  Flask-Cors==3.0.10
  Flask-PyMongo==2.3.0
  itsdangerous==2.0.1
  Jinja2==3.0.2
  MarkupSafe==2.0.1
  pymongo==3.12.1
  python-dateutil==2.8.2
  six==1.16.0
  Werkzeug==2.0.2
  </code></pre>
  <p>My Dockerfile looks like this</p>
  <pre><code>FROM python:3.8-slim-buster
  WORKDIR /api
  COPY requirements.txt requirements.txt
  RUN pip3 install -r requirements.txt
  COPY . .
  CMD [ &quot;python3&quot;, &quot;-m&quot; , &quot;flask&quot;, &quot;run&quot;, &quot;--host=0.0.0.0&quot;]
  </code></pre>
  <p>I am thankful for any help :)</p>
  <p>Project structure is like:</p>
  <pre><code>API
  L venv
  L app.py
  L Dockerfile
  L requirements.txt
  </code></pre>