Dive: Deep Exploration of Docker Images
Introduction
Dive is a powerful command-line utility written in Go that enables developers to inspect Docker images layer-by-layer. With over 53,276 GitHub stars, dive has become an essential tool in the container ecosystem. Unlike standard Docker inspection commands, dive provides an interactive terminal UI that visualizes image contents while showing exactly what’s changed between layers.
Docker images often grow unexpectedly large during development, leading to slow builds, increased storage costs, and longer deployment times. Dive solves these problems by enabling developers to:
- Identify wasted space in Docker images
- Understand layer composition and ordering
- Verify that sensitive files aren’t included accidentally
- Optimize Dockerfiles by analyzing layer efficiency
- Compare different image versions
For réflexions building containerized applications, dive provides invaluable insights that help optimize image size and security - critical factors in production environments.
Key Features
1. Interactive Layer Exploration
Dive presents a dual-pane interface showing both the image layer history and file system contents. You can navigate through each layer to see exactly which files were added, modified, or deleted.
2. Efficiency Metrics
Dive calculates and displays an image efficiency score based on wasted space from duplicated files between layers. This metric quickly shows optimization opportunities.
3. Continuous Integration (CI) Integration
Using the --ci flag, dive can be incorporated into CI pipelines to fail builds when images exceed size thresholds or efficiency scores.
4. Multiple Image Sources
Besides Docker Engine, dive supports analyzing images from Docker archives (.tar), Podman, and directly from registries.
###的第一个5. File Tree Analysis
The detailed file tree view shows file sizes, attributes, and permissions. You can easily spot large files that shouldn’t be included in the final image.
6. Layer Filtering
Filter layers by change type (added, modified, removed) to quickly focus on important changes between image versions.
7. Image Comparison
Compare two images side-by-side to analyze differences in file structure and layer history - perfect for debugging “it worked on my machine” issues.
8. Key Bindings
The intuitive keyboard interface allows for quick navigation, filtering, and layer selection without leaving the terminal.
Installation and Setup
Install dive using Go (requires Go 1.16+):
1go install github.com/wagoodman/dive@latest
Alternatively, install via package managers:
1# Homebrew (macOS/Linux)
2brew install dive
3
4# Chocolatey (Windows)
5choco install dive
Verify installation:
1dive --version
2# Expected output: dive version 0.11.0 (or later)
No configuration is required for basic usage. Dive automatically uses your local Docker environment. For CI integration, set these environment variables:
1export CI=true
2export DIVE_CI_FAIL_ON_ERROR=1
Basic Usage
The simplest way to use dive is to analyze a Docker image:
1dive nginx:latest
This command starts the interactive UI:
- Left pane: