Docker
/Intermediate
Reducing Image Size
Definition
The optimization practice of minimizing the final megabyte size of a Docker image to speed up deployments, reduce storage costs, and decrease the security attack surface.
Explain Like I'm New
Putting the app on a diet. A 2-Gigabyte image takes 5 minutes to download to a server. A 50-Megabyte image takes 3 seconds. Faster downloads mean faster auto-scaling when user traffic spikes.
Real World Example
A Python developer creates an app. Using the default `python:3.9` image results in a 1GB file. By switching to `python:3.9-slim`, using Multi-Stage builds, and cleaning up the `apt` cache, the developer reduces the image to 150MB.
Common Use Cases
- •Cost reduction
- •Improving CI/CD speed
- •Security hardening
Interview Questions
basic
- Does a smaller Docker image download faster or slower to a production server?
intermediate
- How does reducing the image size actually improve Security?