Docker 2 – What all different size of images available as base image of docker & Why do we need different types of Docker images?

A full base image like ubuntu:latest is around 70–80 MB and includes a complete OS environment.

A slim image such as ubuntu:20.04-slim is 30–40 MB, providing a smaller version with fewer packages.

The Alpine image (alpine:latest) is extremely lightweight at about 5 MB, ideal for minimal setups.

A Distroless image, like gcr.io/distroless/base, is around 20 MB and contains only the app runtime, with no shell or package manager.

The Scratch image is an empty image (0 bytes), used for static binaries where you control everything included.

A language runtime image like node:18 is quite large, about 900 MB, as it includes the full runtime and build tools.

  • A language slim image, such as node:18-slim, reduces size to around 150 MB by removing unnecessary components.
  • A multi-stage final image is custom-built and typically under 100 MB, optimized by separating build and runtime environments.

Types of Docker Images

1. Base Images

  • These are the foundational images without any application code.
  • Examples: ubuntu, alpine, debian, centos.
  • Use these when you want full control over your environment.
  • Size: Varies, e.g.,
    • ubuntu:latest ~70-80 MB
    • debian:latest ~20-30 MB
    • alpine:latest ~5 MB (very minimal)

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

2. Application Images

  • Built on top of base images and contain your application and dependencies.
  • Examples: Node.js image (node), Python image (python), .NET image (mcr.microsoft.com/dotnet/sdk).
  • These images include runtimes, libraries, and sometimes build tools.

3. Slim Images

  • Smaller variants of official images, stripped down to essential parts.
  • Example: python:3.10-slim, node:18-slim.
  • They omit non-essential components (like documentation, man pages) to reduce size.
  • Size: Usually 50-70% smaller than the full image.

4. Distroless Images

  • Minimal images with only the application and its runtime, no shell or package manager.
  • Good for production to reduce attack surface.
  • Example: Google’s Distroless images.
  • Size: Smaller than base images, but depends on the app.

5. Multi-Stage Build Images

  • Not really a separate type of image, but a build technique.
  • Allows you to build your app in one stage with all tools, then copy only the necessary files into a smaller final image.
  • Results in smaller, optimized final images.

6. Scratch

  • The smallest image possible—an empty image.
  • Used when you want a totally minimal image with only your statically compiled binary.
  • Size: 0 bytes (empty).
  • Common for Go or Rust apps compiled as static binaries.

Leave a Reply

Your email address will not be published. Required fields are marked *