docker-compose مع Postgres وRedis
تشغيل المكدس الكامل بأمر واحد
docker-compose مع Postgres وRedis درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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. 🚀
الأسئلة الشائعة
هل درس «docker-compose مع Postgres وRedis» مجاني؟
نعم — نص درس «docker-compose مع Postgres وRedis» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «docker-compose مع Postgres وRedis»؟
تشغيل المكدس الكامل بأمر واحد تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «docker-compose مع Postgres وRedis»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- كتابة Dockerfile لـ Django
- docker-compose مع Postgres وRedis
- Entrypoints وMigrations وcollectstatic
- أفضل ممارسات صور الإنتاج