Python + Django + PostgreSQL + Redis
Django is a high-level web framework written in Python that follows the MVT pattern and provides out of the box the pieces every application needs: ORM, admin panel, authentication, migrations and protection against the most common web attacks.
This Stack combines it with PostgreSQL as a relational database and Redis as an in-memory store, the typical configuration when the application needs caching, shared sessions or a task queue with Celery.
Services included
Besides your application, the Stack brings up PostgreSQL, Redis, an nginx that receives traffic on port 80, an automatic backups service and the web file manager.
Project structure
.
βββ app
β βββ helloworld
β β βββ __init__.py
β β βββ settings.py
β β βββ urls.py
β β βββ views.py
β β βββ wsgi.py
β βββ manage.py
β βββ requirements.txt
βββ backup
β βββ backup-runner.sh
βββ nginx
β βββ default.conf
βββ .env.example
βββ app.Dockerfile
βββ compose.yaml
Getting started
Install the Stack and bring it up:
docker-deploy-stack --stack python/django-postgres-redis
cd /root/stack/python/django-postgres-redis
docker compose up -d
Then replace the example application with yours, from Git, via SFTP or from the web file manager, following how-do-i-deploy-an-application-on-a-stack.md. Your code goes in the app/ folder.
Whenever you update the code, apply the changes:
docker compose up -d --build
Configuration
Editable values are in the Stackβs .env file:
| Variable | Default | Purpose |
|---|---|---|
APP_PORT |
80 |
Public port of the Stack. |
APP_ENV |
development |
Application environment. |
DB_NAME |
django |
Database name. |
DB_USER |
django |
Database user. |
BACKUP_ENABLED |
1 |
Automatic backups: 1 enabled, 0 disabled. |
BACKUP_INTERVAL_SECONDS |
86400 |
How many seconds between backups. |
BACKUP_RETENTION_DAYS |
7 |
How many days backups are retained. |
POSTGRES_VERSION |
16-alpine |
Image version. |
REDIS_VERSION |
7-alpine |
Image version. |
After changing it, apply the changes with docker compose up -d.
Useful commands
docker compose ps # view the containers that are running
docker compose logs -f # view live logs
docker compose restart # restart the services
docker compose down # stop and remove the containers