This template is designed to spin up a Django project using PostgreSQL, Gunicorn, Nginx, and Certbot (for SSL). It includes setups for both development and production to run the project in a containerized environment.
Motivation: I needed a Django Docker setup for my projects and came across this article The (near) Perfect Dockerfile for Django Applications by Siddharth Sahu. Initially, decided to use this setup, but it was missing or contradicting some features that were essential for projects. So, decided to build and add those features on top. Hence, this template.
Django 5.1
PostgreSQL 16.4
Gunicorn 21.2.0
Nginx 1.27.1
Certbot latest
- Quick setup for Django project with core app.
- Dockerized setup for both development and production environments.
- Auto renewable SSL certificates using Certbot
- Production ready nginx configuration
- Local configured
static
andmedia
directories (you can remove them if you want to use S3 or any other storage service). - Support for postgresql and sqlite databases( sqlite will be used in development when 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. Refer to 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
yeah, that's it! Your project is now running in a production environment.
-
Create a Repository with 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 the 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. Refer totemplate.dev.env
for the necessary variables. -
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. Refer totemplate.dev.env
for the necessary variables. -
Run Docker Compose:
docker compose up --build