Using Docker in Development

Docker support is a new feature in Pegasus as of October 2020. Please report any issues and watch this page for updates.

Pegasus optionally includes support for Docker during development. The Docker development setup can also be used as a foundation for deploying to containerized platforms. See our deployment page for more details.


You need to install both Docker and Docker Compose prior to setting up your environment.

Getting Started

First build your Pegasus project with Docker enabled and using Postgres as a database following the getting started guide.

Enter the project directory

cd {{ project_name }}

Create and start your Docker containers

docker-compose up

Or to run in the background:

docker-compose up -d

Create and run database migrations

docker-compose exec web python makemigrations
docker-compose exec web python migrate --noinput

Load server

Visit http://localhost:8000/ in a browser and you should be up and running!

Architecture and how it works


The Docker configuration is primarily in docker-compose.yml.

There are four containers that start: a Postgres database, a Redis instance (for caching and use as a Celery broker), a web container running your Django process, and a Celery container for background jobs.


The docker environment sets environment variables using the included file. This file also tells your Docker environment to use (which extends as the DJANGO_SETTINGS_MODULE.

The file is automatically ignored by git, so you can put any additional secrets there. It generally should not be checked into source control.

Python environments

The Python environment is run in the containers, which means you do not need to have your own local environment if you are always using Docker for development. Python requirements are automatically installed when the container builds.

However, keep in mind that if you go this route, you will need to run all commmands inside the containers as per the instructions below.

Running management commands

Running commands on the server can be done using docker-compose, as per the migrate command above.

For example, to bootstrap Stripe subscriptions, run:

docker-compose exec web python bootstrap_subscriptions

Or to promote a user to superuser, run:

docker-compose exec web python promote_user_to_superuser

Updating Python packages

If you add or modify anything in your requirements.txt files, you will have to rebuild your containers. This can be done by running:

docker-compose build

After than you can run

docker-compose up

to run your project with the latest dependencies.

Other Resources