Bootstrap your django project inside docker with PostgreSQL support.
- Dockerfile for Django development
- docker-compose.yml file with 2 services: web (Django) and db (PostgreSQL)
- .gitignore file with support for python and Jetbrains software
- .gitlab and .github directories with issue and pull/merge request templates in each
Install cookiecutter:
pip install cookiecutter
cookiecutter https://github.com/vgoebbels/cookiecutter-django-docker-compose.git
Bootstrapping will take some time because the script has to wait for the PostgreSQL container to come up properly to spin up the django container.
What it does:
- Ask you for a project name, slug and description as well as an app name.
- Build the images
- Run
django-admin startproject
with the project name provided - Patch the PostgreSQL connection information into
settings.py
- Append a path of
/
forLOGIN_REDIRECT_URL
andLOGOUT_REDIRECT_URL
at the end ofsettings.py
- Run
manage.py startapp
with the app name provided - Waits 25 seconds for the PostgreSQL container to come up properly and run
manage.py migrate
- Run
manage.py createsuperuser
(will ask you interactively for admin user settings) - Shut down all the cvontainers
To spin up the project after this, change into the project directory and run:
docker-compose up -d
On some hosts the PostgreSQL container comes up too slowly. This leads to an error message in the Python container about the database not being accessible.
If you encounter this pronlem, shut down and restart the Python container with:
docker-compose stop web
docker-compose up -d web
To prevent this from happening again, start both services manually with some delay by:
docker-compose up -d db
docker-compose up -d web