A Docker‑based deployment for a Django web application served behind Nginx, designed for simple, repeatable deployment on a single Linux host (such as an AWS EC2 instance).
This repository demonstrates a clean separation of concerns:
- Django runs as an application container
- Nginx runs as a reverse proxy container
- Docker Compose orchestrates the stack
The setup is intentionally minimal and well‑suited for infrastructure‑as‑code workflows using tools like Ansible.
Client
│
▼
Nginx (container)
│ reverse proxy
▼
Django (container)
- Nginx listens on ports 80/443 and proxies traffic to Django
- Django runs the application server (e.g., Gunicorn)
- Both services run on the same Docker network
.
├── docker-compose.yaml
├── dockerfile_django
├── dockerfile_nginx
├── default.conf
├── requirements.txt
├── manage.py
├── <django_project_files>
└── README.md
- docker-compose.yaml – Defines and orchestrates the Django and Nginx services
- dockerfile_django – Builds the Django application image
- dockerfile_nginx – Builds the Nginx reverse proxy image
- default.conf – Nginx site configuration
- requirements.txt – Python dependencies for Django
On the target host:
- Linux (Ubuntu or Amazon Linux recommended)
- Docker
- Docker Compose v2 (
docker compose)
Verify installation:
docker --version
docker compose versionCreate a .env file in the project root (not committed to git):
DJANGO_SECRET_KEY=your-secret-key
DJANGO_DEBUG=false
DJANGO_ALLOWED_HOSTS=*Additional variables (database, email, etc.) can be added as needed.
From the project root:
docker compose up -d --buildThis will:
- Build the Django image
- Build the Nginx image
- Start both containers in detached mode
Check running containers:
docker compose psView logs:
docker compose logs -fOnce running:
- Application is accessible via http:///
- Nginx proxies requests to the Django container
docker compose downThis project works well on a single EC2 instance. Typical flow:
- Provision EC2
- Install Docker and Compose
- Clone this repository
- Create
.env - Run
docker compose up -d
This repository is designed to be easily automated:
- Ansible installs Docker and dependencies
- Ansible checks out this repo
- Ansible templates
.envand Nginx config - Ansible runs
docker compose up -d
This allows repeatable, idempotent deployments.
For more robust environments, consider:
- Building images in CI and pulling from a registry (ECR/Docker Hub)
- Using AWS SSM Parameter Store or Ansible Vault for secrets
- Adding HTTPS via Let’s Encrypt or an ALB
- Using multiple instances behind a load balancer for zero downtime
- Demonstrate clean Docker‑based service separation
- Provide a foundation for infrastructure‑as‑code workflows
- Keep the setup understandable and extensible
This project is provided as‑is for learning and experimentation.