Back to feed
Dev.to
Dev.to
7/9/2026
How I Cut a Docker Image From 1.2GB to 180MB

How I Cut a Docker Image From 1.2GB to 180MB

Short summary

A practical walkthrough of reducing a Docker image from 1.2GB to 180MB using five techniques: multi-stage builds, slim base images, layer ordering for dependency caching, .dockerignore, and cleaning up within a single RUN layer. The biggest win came from multi-stage builds that excluded the build toolchain from the runtime image. Together these changes cut cold pulls from ~90s to ~12s and cached rebuilds from ~4min to ~20s.

  • Multi-stage builds removed ~500MB of build toolchain from runtime image
  • Switching from node:20 to node:20-slim and proper layer ordering dramatically improved cache hit rates
  • .dockerignore and single-RUN cleanup prevent bloat and secret leakage

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more