Menu

Multi-Stage Dockerfiles for PHP & Node: 70% Smaller Images
📰

Multi-Stage Dockerfiles for PHP & Node: 70% Smaller Images

DEV Community: laravel·Muhammad Ali Mughal·1 day ago
#iIlRBF7J
#devtolaravel#devto#dev#node#build
Reading 0:00
15s threshold

A typical single-stage Dockerfile for a Laravel or Node.js application starts from a full Debian base image, installs gcc , g++ , make , python3 , git , composer , and npm , compiles native extensions and Vite/Next.js frontend assets, and then ships that entire build kitchen straight to production. The result is a 950MB to 1.4GB container image that takes minutes to pull during Kubernetes autoscaling, wastes registry storage, and hands attackers a full C compiler and package manager inside your running container. By splitting your build into multi-stage Dockerfiles , you can drop production image sizes by 70% to 85% while speeding up CI builds. Below are the exact production patterns we use for PHP/Laravel and Node.js workloads.

Why Bloated Single-Stage Images Hurt Both Autoscaling and Security

When our engineering team at Loop Origin audits containerized SaaS platforms, single-stage Dockerfiles are almost always the #1 cause of slow deployments and sluggish horizontal pod autoscaling.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.