docker-compose mit Postgres und Redis
Den gesamten Stack mit einem Befehl starten
docker-compose mit Postgres und Redis ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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:8000Add Postgres
The db service uses the official Postgres image, giving you a real database without installing anything locally.
db:
image: postgres:16Add Redis
The redis service runs the official Redis image, ready to act as a cache or a Celery message broker.
redis:
image: redis:7Connect 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/appWait with depends_on
Use depends_on so web starts after db and redis, keeping your startup order sane.
web:
depends_on:
- db
- redisPersist 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/dataPass 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: passMap 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 -dQuick 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. 🚀
Häufig gestellte Fragen
Ist die Lektion „docker-compose mit Postgres und Redis“ kostenlos?
Ja — der vollständige Text von „docker-compose mit Postgres und Redis“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „docker-compose mit Postgres und Redis“?
Den gesamten Stack mit einem Befehl starten Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Django Academy zu starten?
Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „docker-compose mit Postgres und Redis“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?
Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Eine Django-Dockerfile schreiben
- docker-compose mit Postgres und Redis
- Entrypoints, Migrationen und collectstatic
- Best Practices für Produktions-Images