Motivation: The importance of container image size
Small container images offer the following benefits:
- Reduced build time
- Reduced storage space usage
- Reduced download time
- Faster deployments
- Better security due to smaller surface attack
Image layers
To reduce container image sizes, it’s important to understand that container images are composed of multiple layers ( think of them as intermediate images) which form the final image.
At build time, each Dockerfile instruction creates an extra layer.
FROM ubuntu # 4 layers (base image)
MAINTAINER adolfo@orangemonk.net # 1 layer
RUN mkdir -p /app/bin # 1 layer
RUN apt-get install -y wget # 1 layer
So, generally speaking, reducing image size is the art of reducing the number of layers.