Multi-stage build ใช้หลาย stage FROM ในหนึ่ง Dockerfile — โดย build แอปพลิเคชันใน stage หนึ่ง (พร้อม build tool ทั้งหมด) แล้วคัดลอกเฉพาะ artifact สุดท้ายเข้าไปใน stage สุดท้ายที่สะอาดและเล็กที่สุด วิธีนี้สร้าง image สำหรับ production ที่ เล็กกว่าและปลอดภัยกว่ามาก
ปัญหา: build tool ทำให้ image อ้วน
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.
