Skillpedia
النشر والسحابة (DevOps)40k · #7301

multi-stage-dockerfile

ما الذي تفعله

ينشئ هذا الوكيل ملفات Dockerfile فعّالة لتشغيل البرامج داخل حاويات. ينظم العملية في مراحل، لضمان أن تكون النتيجة النهائية أصغر وأكثر أماناً وأسرع.

متى تستخدمها

  • ✓عندما تريد إنشاء «حزمة» لتشغيل برنامجك في أي مكان.
  • ✓لجعل حزمة برنامجك أصغر ما يمكن.
  • ✓لجعل حزمة برنامجك أكثر أماناً ضد الهجمات.

رابط المهارة

https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أنشئ ملف Dockerfile محسّناً لتطبيق Node.js يستخدم React.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تستخدم تقنية تُسمى «multi-stage builds»، حيث تبني مرحلة البرنامج، ثم تشغّله مرحلة ثانية أنظف. وهذا يضمن أن النتيجة النهائية تحتوي على الضروريات فقط.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Your goal is to help me create efficient multi-stage Dockerfiles that follow best practices, resulting in smaller, more secure container images.

Multi-Stage Structure

  • Use a builder stage for compilation, dependency installation, and other build-time operations
  • Use a separate runtime stage that only includes what's needed to run the application
  • Copy only the necessary artifacts from the builder stage to the runtime stage
  • Use meaningful stage names with the AS keyword (e.g., FROM node:18 AS builder)
  • Place stages in logical order: dependencies → build → test → runtime

Base Images

  • Start with official, minimal base images when possible
  • Specify exact version tags to ensure reproducible builds (e.g., python:3.11-slim not just python)
  • Consider distroless images for runtime stages where appropriate
  • Use Alpine-based images for smaller footprints when compatible with your application
  • Ensure the runtime image has the minimal necessary dependencies

Layer Optimization

  • Organize commands to maximize layer caching
  • Place commands that change frequently (like code changes) after commands that change less frequently (like dependency installation)
  • Use .dockerignore to prevent unnecessary files from being included in the build context
  • Combine related RUN commands with && to reduce layer count
  • Consider using COPY --chown to set permissions in one step

Security Practices

  • Avoid running containers as root - use USER instruction to specify a non-root user
  • Remove build tools and unnecessary packages from the final image
  • Scan the final image for vulnerabilities
  • Set restrictive file permissions
  • Use multi-stage builds to avoid including build secrets in the final image

Performance Considerations

  • Use build arguments for configuration that might change between environments
  • Leverage build cache efficiently by ordering layers from least to most frequently changing
  • Consider parallelization in build steps when possible
  • Set appropriate environment variables like NODE_ENV=production to optimize runtime behavior
  • Use appropriate healthchecks for the application type with the HEALTHCHECK instruction
الأسئلة الشائعة

ما هو Dockerfile؟

هو ملف نصي يحتوي على تعليمات لـ Docker لإنشاء بيئة معزولة (حاوية) يعمل فيها برنامجك.

لماذا تُعد «المراحل المتعددة» أفضل؟

لأنها تفصل أدوات بناء البرنامج عن بيئة التشغيل، فتكون الحاوية النهائية أصغر وأكثر أماناً بكثير.

ما هي «الحاويات» (containers)؟

هي صناديق معزولة تحتوي على كل ما يحتاجه البرنامج ليعمل، مما يسهّل تشغيله على أجهزة مختلفة.

التفاصيل

الوصف الأصلي من المؤلف

Create optimized multi-stage Dockerfiles for any language or framework

repo: github/awesome-copilot

الشعبية

نجوم GitHub
40k
الترتيب
#7301
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة