
Docker Multi-Stage Builds: How I Shrunk My Node.js Image from 1.2GB to 180MB
There is a moment every developer dreads. You finally dockerize your Node.js app, run docker images , and stare at a 1.2GB image wondering how a simple web server got that fat. I have been there. And multi-stage builds changed everything. This is the story of how I took a bloated Docker image from 1.2GB down to 180MB — without sacrificing developer experience or runtime functionality. The Problem With the Naive Approach Most tutorials teach you to write a Dockerfile like this: FROM node:20 WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build EXPOSE 3000 CMD ["node", "dist/index.js"] This works. It really does. But there is a hidden cost. That node:20 base image weighs in at around 1.1GB on its own. Then you pile on your node_modules — including all the devDependencies you need to compile TypeScript, run tests, or bundle assets. By the time Docker finishes building, you have a production image carrying hundreds of megabytes of tools it will never use at runtime.
Continue reading on Dev.to DevOps
Opens in a new tab



