PostgresとRedisを使うdocker-compose
1つのコマンドでフルスタックを起動します
「PostgresとRedisを使うdocker-compose」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. 🚀
よくある質問
「PostgresとRedisを使うdocker-compose」レッスンは無料ですか?
はい。「PostgresとRedisを使うdocker-compose」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。
「PostgresとRedisを使うdocker-compose」で何を学びますか?
1つのコマンドでフルスタックを起動します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Django Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「PostgresとRedisを使うdocker-compose」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDjango Academyレッスンでコードを書いて実行できますか?
はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Django Dockerfileの作成
- PostgresとRedisを使うdocker-compose
- Entrypoints、Migrations、collectstatic
- 本番イメージのベストプラクティス