Category: python
deploying flask with gunicorn nginx docker
Published on 30 Sep 2026
Explanation
Flask's built-in development server is not intended to be the production application server. Gunicorn can serve the Flask application in production.
Code:
gunicorn --bind 0.0.0.0:8000 app:app
Explanation
Gunicorn can run multiple worker processes to handle concurrent requests.
Code:
gunicorn \ --workers 4 \ --bind 0.0.0.0:8000 \ app:app
Explanation
Nginx can act as a reverse proxy in front of Gunicorn and handle incoming HTTP or HTTPS traffic.
Code:
Internet | v Nginx :80/:443 | v Gunicorn :8000 | v Flask App
Explanation
A Dockerfile can package the Flask application and its Python dependencies into a portable container.
Code:
FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]
Explanation
A production architecture can combine Nginx, Gunicorn, Flask, database services, and Docker containers.
Code:
Client | v Nginx | v Gunicorn | v Flask Container | +---- PostgreSQL | +---- Redis | +---- External Services