Hackforge Academy

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

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community