A complete Django setup, running in Docker
Switch branches/tags
Nothing to show
Clone or download
Matthew Miller
Matthew Miller Upgrade project dependencies
Github warned about a security vulnerability in Django 2.0.4 so I took an opportunity to update all of the project’s dependencies to their latest stable versions. This includes upgrading from Python 3.6 to 3.7.
Latest commit 5c23213 Oct 6, 2018


Docker'd Django

Django, Postgres, and Redis, all in Docker

This is a boilerplate repo intended for quickly starting a new Django project with PostgreSQL and Redis support, all running within Docker containers. A Nginx service is also defined to enable immediate access to the site over port 80.


  • Docker
  • Pipenv
    • Make sure Python3 is available
    • Enables pipenv install to set up libraries locally for the editor to crawl. The Django container also uses Pipenv to install dependencies to encourage use of this new Python package management tool.

Getting started

  1. Clone this repo
  2. Delete the .git folder
    • rm -rf .git/
  3. Create a new git repo
    • git init
    • git add .
    • git commit -m "Initial Commit"
  4. Install Python dependencies in a Python3 virtual environment
    • pipenv install --three
  5. Create a new Django project
    • pipenv run django-admin startproject appname _app/
  6. Make the following changes to your Django project's settings.py:
# appname/settings.py
import os

# SECURITY WARNING: keep the secret key used in production secret!

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False) == 'true'


    # ...snip...

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.getenv('POSTGRES_USER'),
        'USER': os.getenv('POSTGRES_USER'),
        'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
        'HOST': 'db',
        'PORT': 5432,

STATIC_ROOT = 'static'

# django-redis
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://redis:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
  1. Update the .env file to specify values for the environment variables defined within
  2. Start Django for development
    • docker-compose up



Builds the Django container. The container is derived from the standard python:3.7 image and will run Django's colletstatic when being built.


Tasked with spinning up three containers: the above container for Django, one for PostgreSQL, and one for Redis.

By default an Nginx container is also created to reverse-proxy requests to Django and serve static files. In this configuration, the Django server will be available on port 80 during production.

If the Nginx container is removed, Docker can be accessed directly on port 8000. Static files can then be served from the static_files_volume Docker volume.


Loads automatically when running a standard docker-compose up. These values are intended for development purposes as they tweak the container configurations in the following way:

  • Make the Postgres container accessible externally on port 5432
  • Make the site available through Nginx at http://localhost:8000
  • Start gunicorn to reload when it detects a file change
  • Set an environmental flag telling Django that it is running in debug mode


Includes Python packages needed to make Django, Postgre, and Redis work together.


Contains environment variables for the containers. Several variables are included for configuring Postgres and Django secrets.


Defines some common settings to help ensure consistency of styling across files.


Configures the flake8 Python linter. Includes a few common settings to my personal preferences.


Helps configure the Python plugin to lint with flake8. A placeholder Python interpreter setting is left in to simplify pointing to the local virtual environment created with Pipenv.


Defines settings for gunicorn, including a port binding, workers, and an gunicorn-specific error log.


Establishes a reverse-proxy to Django, and serves Django static files.