0Pricing
Django Academy · Lesson

docker-compose with Postgres and Redis

Run the full stack with one command.

docker-compose with Postgres and Redis is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Command, Whole Stack

docker-compose defines many containers in one file, so Django, Postgres, and Redis start together with a single command. 🧩

The compose File

Everything lives in docker-compose.yml, where each container you need becomes an entry under the services key.

services:
  web:
  db:
  redis:

The web Service

Your web service builds from your Dockerfile and runs Django, the heart of the whole stack.

web:
  build: .
  command: gunicorn config.wsgi:application --bind 0.0.0.0:8000

Add Postgres

The db service uses the official Postgres image, giving you a real database without installing anything locally.

db:
  image: postgres:16

Add Redis

The redis service runs the official Redis image, ready to act as a cache or a Celery message broker.

redis:
  image: redis:7

Connect by Service Name

Compose gives each service a DNS name, so Django reaches Postgres at the host db, not localhost.

DATABASE_URL=postgres://user:pass@db:5432/app

Wait with depends_on

Use depends_on so web starts after db and redis, keeping your startup order sane.

web:
  depends_on:
    - db
    - redis

Persist Data with Volumes

A named volume stores Postgres data outside the container, so your rows survive restarts and rebuilds.

db:
  volumes:
    - pgdata:/var/lib/postgresql/data

Pass Configuration as Env

Feed secrets and settings through environment or an env_file, keeping config out of your image.

db:
  environment:
    POSTGRES_DB: app
    POSTGRES_PASSWORD: pass

Map Ports to Your Host

The ports key forwards a container port to your machine, so you can open the app in a browser.

web:
  ports:
    - "8000:8000"

Bring It All Up

Run docker compose up and the entire stack boots together; add -d to run it in the background.

docker compose up -d

Quick Check

How does your web container reach the database in Compose?

Recap

You wired a full stack in docker-compose: web, db, and redis services, connected by name, with volumes for data and one command to launch. 🚀

Frequently asked questions

Is the “docker-compose with Postgres and Redis” lesson free?

Yes — the full text of “docker-compose with Postgres and Redis” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “docker-compose with Postgres and Redis”?

Run the full stack with one command. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “docker-compose with Postgres and Redis” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Writing a Django Dockerfile
  2. docker-compose with Postgres and Redis
  3. Entrypoints, Migrations, and collectstatic
  4. Production Image Best Practices
← Back to Django Academy