This project demonstrates how to Dockerize a full-stack web application using Django and PostgreSQL.
The application is containerized using Docker, orchestrated with Docker Compose, and the application image is published on Docker Hub.
This project was built as part of the #90DaysOfDevOps challenge (Day 36).
This is a simple Django Blog application that allows users to create and view blog posts.
Features:
- Django backend
- PostgreSQL database
- Admin panel for managing posts
- Gunicorn as the production WSGI server
- Docker multi-stage build
- Non-root container execution
- Docker Compose orchestration
- Persistent PostgreSQL storage
Architecture:
Browser
↓
Gunicorn
↓
Django Application
↓
PostgreSQL Database
.
├── blog/ # Django blog app
├── config/ # Django project settings
├── templates/ # HTML templates
├── Dockerfile.multistage
├── docker-compose.yml
├── requirements.txt
├── manage.py
├── .env
└── README.md
git clone <your-repo-url>
cd <project-folder>Example:
DEBUG=True
SECRET_KEY=changeme
DB_NAME=django_db
DB_USER=django_user
DB_PASSWORD=django_pass
DB_HOST=db
DB_PORT=5432
POSTGRES_DB=django_db
POSTGRES_USER=django_user
POSTGRES_PASSWORD=django_pass
Run:
docker compose upDocker Compose will:
- Pull the Django image from Docker Hub
- Start the PostgreSQL container
- Create the network and volumes
- Start the Django application container
Open your browser:
http://localhost:8000
Create an admin user:
docker compose exec django-app python manage.py createsuperuserThen visit:
http://localhost:8000/admin
The application uses the following environment variables.
| Variable | Description |
|---|---|
| DEBUG | Enable/disable debug mode |
| SECRET_KEY | Django secret key |
| DB_NAME | PostgreSQL database name |
| DB_USER | PostgreSQL username |
| DB_PASSWORD | PostgreSQL password |
| DB_HOST | Database hostname (db service) |
| DB_PORT | Database port |
| POSTGRES_DB | PostgreSQL database |
| POSTGRES_USER | PostgreSQL user |
| POSTGRES_PASSWORD | PostgreSQL password |
Docker image for the application:
yasheroic/django-app:latest
To pull manually:
docker pull yasheroic/django-app:latestdocker compose downTo remove volumes as well:
docker compose down -v- Python
- Django
- PostgreSQL
- Docker
- Docker Compose
- Gunicorn
Built as part of the #90DaysOfDevOps learning challenge.