Setting up a SaaS app with Django Cookie Cutter and Docker all ready to go

This is a detailed look at setting up a projection level django project using cookie-cutter django.  I explore the different choices and project layout of cookiecutter django as we go along setting up the project.

A long long time ago, so long time ago, no one knows how long ago (ok maybe a couple of years back), I installed docker on my machine and created a few containers. So, then, my machine had less space and I wanted to remove a few of those containers because I have no use for them. I try to delete them, and lo and behold, that does not work. Docker internally uses a different filesystem structure and it has some issues with deleting containers. There had been open tickets for it for sometime and yet it was not prioritized. There is nothing I could do short of purging docker and all its data from my system. Bump 🙁 .

So you can understand my reluctance to install docker directly on my machine. I always setup a vagrant machine and install docker in that. As an added bonus, I can also ensure the same setup works on any vanilla box. I use the Ubuntu LTE version.

The sequence of steps I follow to install docker.

To Install docker:

To install docker-compose:

If you run into issues while installing docker like

docker-ce : Depends: libseccomp2 (>= 2.3.0) but 2.2.3-3ubuntu3 is to be installed

run the following commands

    sudo apt-get install aptitude #Incase you don't have aptitude installed already
    sudo aptitude install docker-ce

The aptitude command will give you different options to workaround the dependency problem.

Next, we need to ensure we have pip and python 3.6.
sudo apt-get install libssl-dev

pip3.6 install cookiecutter

Change the current dir to the one when the code will be developed


cookiecutter will ask you a set of questions to setup django.
Use the following url to understand the options

One of the questions will ask for a ‘slug’ for the project. This will be sued for your repo and in other places where a Python-importable version of your project name is needed. Enter your project’s slug without dashes or spaces.

vagrant@ubuntu-bionic:/vagrant$ cookiecutter

You've downloaded /home/vagrant/.cookiecutters/cookiecutter-django before. Is it okay to delete and re-download it? [yes]: no
Do you want to re-use the existing version? [yes]: yes
project_name [My Awesome Project]: Site Fitness
project_slug [site_fitness]: 
description [Behold My Awesome Project!]: Website Availability & Status Checker
author_name [Daniel Roy Greenfeld]: Sharmila Gopirajan Sivakumar
domain_name []:
email []:
version [0.1.0]:

Select open_source_license:
1 - MIT
2 - BSD
3 - GPLv3
4 - Apache Software License 2.0
5 - Not open source

Choose from 1, 2, 3, 4, 5 [1]: 5

timezone [UTC]: IST
windows [n]: n
use_pycharm [n]: y
use_docker [n]: y

Select postgresql_version:
1 - 10.4
2 - 10.3
3 - 10.2
4 - 10.1
5 - 9.6
6 - 9.5
7 - 9.4
8 - 9.3
Choose from 1, 2, 3, 4, 5, 6, 7, 8 [1]: 1

Select js_task_runner:
1 - None
2 - Gulp
Choose from 1, 2 [1]: 2

custom_bootstrap_compilation [n]: y
use_compressor [n]: y
use_celery [n]: y
use_mailhog [n]: y
use_sentry [n]: y
use_whitenoise [n]: y
use_heroku [n]: n
use_travisci [n]: y
keep_local_envs_in_vcs [y]: y
debug [n]: y

 [WARNING]: Docker and Gulp JS task runner working together not supported yet. You can continue using the generated project like you normally would, however you would need to add a JS task runner service to your Docker Compose configuration manually.

 [SUCCESS]: Project initialized, keep up the good work!

There will be a folder created with the name containing all the generated code.

cd <slug>

You should find the following files.

README.rst  config  gulpfile.js  locale  production.yml  requirements  sitefitness   compose     docs    local.yml  package.json                           pytest.ini      setup.cfg
  • To setup docker locally we need local.yml file. For deployment we need production.yml
  • README.rst contains the following setup instructions.
  • config contains settings folder, and
  • gulpfile.js contains the sass compilation, autoprefixing css, minification, and js minification code
  • [WARNING]: Docker and Gulp JS task runner working together not supported yet. You can continue using the generated project like you normally would, however you would need to add a JS task runner service to your Docker Compose configuration manually
  • local.yml and production.yml are configurations files for docker-compose to setup local environment and production environment respectively. Both spin up containers for django, postgres, redis, celeryworker, celerybeat and flower. local.yml also setups up mailhog for local email testing, whereas production.yml additionaly setups up caddy for hosting. The filesystem within docker is not persistent. So we just have to configure the following disk volumes in the yml file that map to host filesystem to enable peristence for data.
    • local_postgres_data: {}
    • production_postgres_data: {}
    • local_postgres_data_backups: {}
    • production_postgres_data_backups: {}
    • production_caddy: {}
  • requirements directory contains 3 requrements file. base.txt contains packages common to both local and production environment. local.txt and production.txt include requirements from base.txt and further more add local/production specific packages.
  • package.json maintains the requirements for gulp.
  • pytest.ini – configuration file for pytest module
  • site_fitness – All apps reside here.
  • I am not sure about I have no use for locale yet.

If you going to use any ip other than "localhost", "", "" to access the server, add that ip to the INTERNAL_IPS or ALLOWED_HOSTS setting in config/settings/ For example, I will be running the server in a Vagrant machine, whose ip will be So I will add that IP to ALLOWED_HOSTS setting.

Yay! all the setup is done!
Lets begin building.

docker-compose -f local.yml build

This starts downloading the docker images for postgres, mailhog, django, redis, celery and setup them up.

To bring up django and postgresql, run

docker-compose -f local.yml up

Change the volumes params in local.yml. Make them point to the local host directory for persistence.

Setup a blog

The main contention was between Zinnia and Wagtail-Puput.

Why Zinnia?

Zinnia is a fairly mature blogging platform based on Django. It replicates most of wordpress features. Wagtail gives a great modular way to setup a CMS and I have been seeing rave reviews for it. But it feels more like Lego blocks than a full-fledged system (maybe this is my lack of understanding, but not because of lack of trying). Zinnia on the other hand can be easily setup in a second. The admin ui is quite lacking compared to Wagtail-Puput but hey, if I do have to migrate to Puput, Puput has a zinna to Puput migrator 😉

To install, add the following line to requirements/base.txt

#zinnia blog

Then run the following to install zinnia and its dependencies.

sudo docker-compose -f local.yml build

the following line to config/settings/

 ZINNIA_APPS = ['django_comments',

Zinnia should come after LOCAL_APPS because one of the local apps extends the User Model. Adding Zinnia before registering the User Model will result in the error LookupError: Model 'users.User' not registered..

Zinnia needs a little more setup. Please refer to

To setup bootstrap theme for Zinnia

  • Add the following line to requirements/base.txt
  • Include the following line in config/settings/ before the line zinnia in ZINNIA_APPS


  • Once installed, add app_namespace.Loader to the TEMPLATE_LOADERS setting of your project.

… # Other template loaders
With Django >= 1.8 app_namespace.Loader should be added to the ‘loaders’ section in the OPTIONS dict of the DjangoTemplates backend instead. Note: With Django 1.8, app_namespace.Loader should be first in the list of loaders.

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'loaders': [
  • Run

    sudo docker-compose -f local.yml build
    sudo docker-compose -f local.yml run

Leave a Reply

Your email address will not be published. Required fields are marked *