マルチステージビルドは、1つのDockerfile内で複数のFROMステージを使い、アプリケーションをビルドステージ(すべてのビルドツール含む)で構築し、最終的なアーティファクトだけをクリーンで最小限の最終ステージにコピーします。これにより、はるかに小さく、より安全な本番イメージが生成されます。
問題:ビルドツールがイメージを肥大化させる
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.
