Create a Running Docker Container With Gunicorn and Flask

Let’s begin by creating a minimal Flask application:

from flask import Flask
app = Flask(__name__)


@app.route('/')
@app.route('/index')
def index():
   return 'Hello world!'

Next, let’s write the command that will run the  Gunicorn  server:

#!/bin/sh
gunicorn --chdir app main:app -w 2 --threads 2 -b 0.0.0.0:8000

The parameters are pretty much self-explanatory: We are telling Gunicorn that we want to spawn two worker processes running two threads each. We are also accepting connections from the outside and overriding Gunicorn’s default port (8000).

#gunicorn #kubernetes #python #docker

Create a Running Docker Container with Gunicorn and Flask
3.00 GEEK