البنايات متعددة المراحل تستخدم عدة مراحل FROM في Dockerfile واحد — بناء التطبيق في مرحلة واحدة (مع جميع أدوات البناء) ونسخ المصنوعات النهائية فقط إلى مرحلة نهائية نظيفة وبسيطة. هذا ينتج صور إنتاجية أصغر بكثير وأكثر أماناً.
المشكلة: أدوات البناء تنتفخ الصورة
Building an app needs build tools (compilers, dev dependencies, SDKs), but the
FINAL image shouldn't include them:
→ they bloat the image (larger size, slower deploys)
→ they increase the attack surface (more software = more vulnerabilities)
→ You want only the built artifact + its runtime in the final image.
