You can inspect each layer in a Docker image using `dive`

Dive is a command-line tool that lets you explore Docker images layer-by-layer, showing exactly what each layer adds, modifies, or removes. It’s perfect for understanding image structure and identifying ways to reduce image size.

Installation:

# macOS
brew install dive

# Linux (various package managers available)
# Or via Docker
docker pull wagoodman/dive

Basic usage:

dive <image-name>

What it shows:

Build and analyze in one command:

dive build -t my-image:latest .

CI/CD integration:

Set efficiency thresholds to fail builds with bloated images:

CI=true dive <image-name>

This tool is invaluable for optimizing Dockerfiles, understanding why images are large, and catching unnecessary files that accidentally made it into production images.

Original source