2.6 KiB

Dockerised Django

This is a Dockerised Django Project template

Getting started

  1. Clone this repo, cd into it, and copy the .env file:
git clone
cd repo
cp .env.example .env
  1. Edit the .env file and review its settings. At a minimum, you'll probably want to uncomment DEBUG=true for testing

  2. Start Django

  • To do so using Docker:

    docker-compose up -f -d
  • To do so using a Python venv:

    NOTE: These instructions are only tested on macOS and Linux

    Perform the initial set-up (do this only once):

    # Create a virtual environment
    python3 -m venv .venv
    # Activate virtual environment
    . .venv/bin/activate
    # Install Python dependencies
    pip install -r django/requirements.txt
    # Change to the django dir
    cd django/
    # Run the Docker entrypoint script to set up an initial superuser etc
    cd ..

    Start up Django (do this every time):

    # Activate virtual environment
    . .venv/bin/activate
    # Change to the django dir
    cd django/
    # Start Django
    ./ runserver
  1. Log into admin console at http://localhost:8000/admin as root/root

Creating your first app

Now you've got Django up and running, you should be at the point where you can follow the Django documentation to create your first app. The short version of what you need to do from here is:

  1. Create an app:

If using Docker:

docker-compose exec app ./ startapp myapp

If using a virtual environment:

./ startapp myapp
  1. Edit both django/myproject/ and django/myproject/, search for myapp, and uncomment the line as instructed.

  2. Set up appropriate views in django/myapp/, and URLs in django/myapp/, before browsing to http://localhost:8000/


By default there is no docker-compose.yml, so docker-compose up won't work without specifying one of the other files. is designed for use during development. You probably also want to uncomment the DEBUG line in the .env file in this case. is designed for production.

docker-compose.traefik.yml is designed for production when using Traefik as a HTTP proxy

For convenience, any of these files could be copied or symlinked to docker-compose.yml so you don't need to specify the file with docker-compose -f file.yml.