Chapter 3: The Dockerfile — Multi-Stage Build
3.1 Why Multi-Stage Builds?
A naive Dockerfile installs everything (Composer, Node.js, npm, dev dependencies) in a single layer. The resulting image is hundreds of megabytes larger than it needs to be and may contain security vulnerabilities from build tools that have no business being in production.
Multi-stage builds solve this by separating the build environment from the runtime environment:
• Stage 1 (builder): Has Composer, Node.js, npm, and all dev tooling installed. Installs production PHP dependencies and compiles JavaScript assets.







