Containerization of a Flask application

Containerization of a Flask application

Flask can be seen as the equivalent of Express for Python. However, although an express application is basically production ready, a Flask app outputs the following when executed by itself:

WARNING: This is a development server. Do not use it in a production deployment.

flask_app.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

# Allow the app to be run in devvelopment mode if run using python3 main.py
if __name__ == "__main__":
    app.run('0.0.0.0', 7193)

requirements.txt

Flask
gunicorn

Dockerfile

FROM python:3.6

WORKDIR /usr/src/app
COPY . .


RUN pip3 install -r requirements.txt

# Expose port
EXPOSE 7557

# Run the app
CMD [ "gunicorn", "flask_app:app", "-b 0.0.0.0:7557"]