Docker Images: Why Is My Build 2GB?
Shrink your Docker images from 2GB to 150MB using multi-stage builds, Alpine base images, and proper package management.
Sarwar Hossain Lead Software Engineer
Nov 25, 2025
4 min read
Docker Images: Why Is My Build 2GB?
Last Updated: November 2025
Scope: Docker, Node.js, Python
The Audit
docker images
# Look at the SIZE column
🚩 Red Flags:
- Node.js app >500MB
- Python app >1GB
The Fixes
Fix 1: Multi-Stage Builds
# ❌ Bad: Includes build tools in final image (800MB+)
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["node", "dist/index.js"]
# ✅ Good: Build stage separate from runtime (150MB)
FROM node:18 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node:18-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]
Fix 2: Use Alpine Base Images
FROM node:18-alpine # 40MB instead of 350MB
FROM python:3.11-slim # 120MB instead of 900MB
Fix 3: Clean Up Package Managers
RUN npm ci --only=production && npm cache clean --force
# OR
RUN pip install --no-cache-dir -r requirements.txt
The Checklist
- Using multi-stage builds?
- Using alpine/slim base images?
- Cleaning package manager cache?
Need Engineering Help?
Let's Build Something Scalable
We apply these same engineering principles to client projects. Ready to upgrade your stack?