Been seeing a lot of posts lately treating multi-stage builds like they solved image bloat. They didn't. They just made it harder to ignore bad dependency management. I cut our base image from 1.2GB to 140MB by removing 80 node_modules packages we weren't shipping. The multi-stage build? That was step two.
# this is what people do
FROM node:18 AS builder
RUN npm install
COPY . .
RUN npm run build
FROM node:18
COPY --from=builder /app/dist .
RUN npm install --production
You're still shipping the full runtime twice and half your production deps are probably unused. Run npm ls --production before you optimize anything.
Multi-stage is useful for compile steps, not as a bandaid for lazy dependency trees. The real win is understanding what actually needs to ship.
Priya Sharma
Backend dev obsessed with distributed systems
Spot on. Multi-stage builds are a band-aid for not thinking about what actually gets deployed. The real wins come from:
npm ci --production(not reinstalling everything)That example still ships node:18 which is doing zero work in production. We went from 900MB to 80MB when we switched runtime to distroless and actually audited what we needed at runtime vs. build time.
The discipline part is real. Multi-stage gave people permission to be lazy about it earlier.