Entrypoints وMigrations وcollectstatic
تشغيل خطوات بدء التشغيل داخل الحاوية
Entrypoints وMigrations وcollectstatic درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Startup Steps Matter
Before serving traffic, a container often needs to run migrations and gather static files. Let's automate those startup steps. ⚙️
What an Entrypoint Is
An entrypoint is a script that runs every time the container starts, right before your main command takes over.
Write the Script
Create entrypoint.sh with a shebang line, so the container knows to run it with the shell.
#!/bin/sh
set -eApply Migrations on Boot
Run migrate inside the entrypoint, so your database schema is always current when the app starts.
python manage.py migrate --noinputGather Static Files
Run collectstatic to copy CSS and JS into one folder that your server can serve in production.
python manage.py collectstatic --noinputHand Off with exec
End the script with exec so your app becomes process 1 and receives stop signals cleanly.
exec "$@"Make It Executable
Set the script as executable in your Dockerfile so the container can actually run it on startup.
RUN chmod +x entrypoint.shWire It in the Dockerfile
Point ENTRYPOINT at your script, then keep CMD as the command it should run last.
ENTRYPOINT ["./entrypoint.sh"]
CMD ["gunicorn", "config.wsgi"]Why --noinput
The --noinput flag stops Django from pausing for prompts, which is essential for unattended container startups.
Wait for the Database
Postgres may boot slowly, so it helps to wait for the db port before migrating to avoid connection errors.
until nc -z db 5432; do sleep 1; doneWatch the Logs
Use docker compose logs to confirm migrations ran and static files were collected on startup.
docker compose logs -f webQuick Check
Why end an entrypoint script with exec on the main command?
Recap
Your entrypoint now runs migrate and collectstatic with --noinput, waits for the db, then execs the app as PID 1. Boot-ready every time. ✅
الأسئلة الشائعة
هل درس «Entrypoints وMigrations وcollectstatic» مجاني؟
نعم — نص درس «Entrypoints وMigrations وcollectstatic» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «Entrypoints وMigrations وcollectstatic»؟
تشغيل خطوات بدء التشغيل داخل الحاوية تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «Entrypoints وMigrations وcollectstatic»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- كتابة Dockerfile لـ Django
- docker-compose مع Postgres وRedis
- Entrypoints وMigrations وcollectstatic
- أفضل ممارسات صور الإنتاج