dive
A terminal tool for examining Docker or OCI image layers, file changes, and wasted space.
Why consider dive?
Dive is an open-source terminal tool for exploring Docker and OCI image layers, discovering file modifications across builds, and identifying wasted space to shrink container sizes.
Learn dive by building
Practical setup notes, real use cases, and copy-ready examples in one focused guide.
In this guide3 sections
Inspecting and Optimizing Container Images with Dive
When building containerized applications, image size directly impacts deployment latency, network transfer times, and storage overhead. Unintentional bloat often creeps into container images when build steps create intermediate artifacts, duplicate assets across layers, or fail to clean up package manager caches within the same RUN instruction. According to the official README, Dive is a tool for exploring a Docker image, layer contents, and discovering ways to shrink the size of your Docker/OCI image.
The project is hosted in the Dive GitHub Repository and is made available under the open-source MIT License. It provides both an interactive terminal user interface (TUI) and an automated non-interactive continuous integration mode.
Layer Inspection and File Tree Navigation
Container images are composed of stacked filesystem layers. Understanding what is introduced at each layer is necessary when diagnosing unexpected bloat. In Dive's interactive mode, the terminal interface splits the display into distinct functional areas:
- Layer Breakdown: As you select a layer on the left, you are shown the contents of that layer combined with all previous layers on the right. You can navigate through the layer history to see how each Dockerfile instruction modified the root filesystem.
- File Tree State: Files that have changed, been modified, added, or removed are indicated in the file tree. This color-coded and marked view makes it immediately clear whether an instruction unintentionally modified permissions or created unexpected temporary files.
- Space Utilization Metrics: The lower left pane shows basic layer info and an experimental metric that will guess how much wasted space your image contains. This calculation highlights duplicate files across layers, moved paths, and incomplete removals.
Navigating the filesystem view allows developers to trace individual large files back to the exact Dockerfile line responsible for generating them.
Analyzing Images with the Command-Line Interface
You can analyze local images directly using the standalone binary or by running Dive through Docker without permanent host installation.
To analyze an existing image on your local machine, run the tool with an image tag:
dive <your-image-tag>For teams that prefer not to install the binary natively, Dive can run as a temporary container sharing the host Docker daemon socket:
docker run -ti --rm -v /var/run/docker.sock:/var/run/docker.sock docker.io/wagoodman/dive nginx:latestDive also supports building and analyzing in a single unified step with dive build -t <tag> ., substituting standard docker build commands during local iteration loops.
Automated CI Pipeline Integration
Interactive inspection is effective for manual debugging, but preventing regressions requires automated enforcement during pull request verification. Dive allows teams to evaluate container images programmatically in CI pipelines without launching the terminal user interface.
Setting the CI=true environment variable instructs Dive to run non-interactively:
CI=true dive <your-image>In this mode, Dive will analyze an image and get a pass/fail result based on the image efficiency and wasted space. When configured alongside custom threshold rules in .dive.yaml—such as maximum allowable wasted bytes or minimum required efficiency ratios—Dive can automatically exit with a non-zero exit code to fail continuous integration builds whenever an image violates size policies.
Related tools
More options with a similar category or technology profile.
diskus
Minimal, fast alternative to du -sh written in Rust using multi-threaded directory traversal.
peco
Simplistic interactive filtering tool for Unix pipelines, process lists, and file trees.
Dapr CLI
Command-line tool for managing Dapr distributed application runtime environments and sidecars.
Freeze
Generate beautiful image screenshots and SVGs of code snippets and terminal outputs.