This template is designed to quickly set up a Django project using PostgreSQL, Gunicorn, Nginx, and Certbot (for SSL). It supports both development and production environments, facilitating the running of your project in a containerized setup.
I needed a robust Docker setup for my Django projects and came across this article The (near) Perfect Dockerfile for Django Applications by Siddharth Sahu. While the original setup was a good start, it lacked several essential features for my projects. As a result, I decided to enhance it and create this template.
Technology | Version | Badge |
---|---|---|
Django | 5.1 | |
PostgreSQL | 16.4 | |
Gunicorn | 21.2.0 | |
Nginx | 1.27.1 | |
Certbot | latest |
- Quick setup for Django projects with a core application.
- Dockerized environments for both development and production.
- Automatic SSL certificate renewal using Certbot.
- Production-ready Nginx configuration.
- Local
static
andmedia
directories (configurable for S3 or other storage services). - Support for both PostgreSQL and SQLite databases (SQLite will be used in development if PostgreSQL isn't available).
-
Create a
.prod.env
File: In the root directory of your project, create a.prod.env
file with the required environment variables. Use the providedtemplate.prod.env
for guidance. -
Run Docker Compose: Execute the following command to build and run your project in a production environment:
docker compose -f docker-compose.prod.yml up --build
Your project is now running in a production environment!
-
Create a Repository from This Template:
-
Clone the Repository Locally:
git clone <YOUR-repository-url>
-
Create a Virtual Environment:
python3 -m venv venv
-
Activate the Virtual Environment:
source venv/bin/activate
-
Install Requirements:
pip install -r requirements.txt
-
Create a
.dev.env
File: In the root directory of the project, create a.dev.env
file with the required environment variables, referencingtemplate.dev.env
. -
Start the Development Server:
python manage.py runserver
-
Clone the Repository:
git clone <repository-url>
-
Create a
.dev.env
File: In the root directory of the project, create a.dev.env
file with the required environment variables, referencingtemplate.dev.env
. -
Run Docker Compose:
docker compose up --build
=======