Skip to main content

On This Page

From 1.2GB to 54MB: My Docker Image Went on a Diet

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

From 1.2GB to 54MB: My Docker Image Went on a Diet

Tushar Sharma optimized a Node.js Docker image from 1.2GB to 54MB, slashing build times and registry costs. The transformation used multi-stage builds and Alpine Linux, reducing the image by 95%.

Why This Matters

Default base images like Debian-based Node.js (350MB+) are often bloated with unnecessary tools and libraries. In practice, developers frequently include dev dependencies, logs, and build tools in production images, leading to slow deployments, increased registry costs, and storage bloat. The original 1.2GB image caused CI/CD pipelines to crawl and wasted resources across teams.

Key Insights

  • “Switching to node:16-alpine reduced image size from 1.2GB to 250MB (Tushar Sharma, 2025)”
  • “Multi-stage builds eliminated dev tools, cutting image size by 75% (Tushar Sharma, 2025)”
  • “Dockerignore and cleanup reduced final image to 54MB (Tushar Sharma, 2025)“

Working Example

# Original Dockerfile (1.2GB)
FROM node:16
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
CMD ["node", "index.js"]
# Optimized Dockerfile (54MB)
# Stage 1: Build
FROM node:16-alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:16-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY package*.json ./
RUN npm install --production
EXPOSE 3000
CMD ["node", "dist/index.js"]
# .dockerignore
node_modules
*.log
*.tmp
.git
.env
Dockerfile
*.md

Practical Applications

  • Use Case: Node.js microservices with minimal footprint
  • Pitfall: Using default Debian-based images without optimization (bloats images by 300%+)

References:


Continue reading

Next article

From 40% to 100% SQL Generation Accuracy: Why Local AI Needs Self-Correction, Not Perfect Prompts

Related Content