Member-only story
How I Reduced My Docker Image Size from 1.8GB to 36MB
Docker is an incredible tool for containerization, but it’s easy to unknowingly build inefficient, bloated images. At first, I found myself with a whopping 1.8GB Docker image for my Go application. After applying some key optimization techniques, including multi-stage builds, I successfully reduced the image size to 36MB. Here’s how I did it, along with some insights on further optimization.
The Moment of Realization
As I stared at the bloated image, it dawned on me: my Dockerfile was a mess. It wasn’t just big — it was inefficient, insecure, and filled with unnecessary clutter. Here’s the original Dockerfile that caused my pain:
After building this, I was shocked by the huge size of the image, weighing around 1.87GB. I thought Go would be better in terms of size. I knew Node.js images were more than 2GB in size but expected better from Go. I almost forgot about it, but then came the time to deploy.
While trying to deploy to DigitalOcean, I noticed there were size limits, at least on the free plan, and this led me to find alternatives.