Dive — Explore Docker Image Layers and Optimize Size
Dive is a tool for exploring Docker image contents layer by layer. It shows exactly what changed in each layer, identifies wasted space, and helps you optimize your Dockerfiles for smaller, more efficient container images.
What it is
Dive is a CLI tool for exploring Docker image contents layer by layer. It shows exactly what files were added, modified, or removed in each layer, identifies wasted space from files that are added then deleted in subsequent layers, and provides an efficiency score. Dive helps you optimize Dockerfiles for smaller, more efficient container images.
Dive is for DevOps engineers and backend developers who build Docker images and want to reduce image size, speed up deployments, and lower storage costs.
The project is actively maintained with regular releases and a growing user community. Documentation covers common use cases, and the open-source nature means you can inspect the source code, contribute fixes, and adapt the tool to your specific requirements.
How it saves time or tokens
Without Dive, debugging large Docker images requires guessing which layer added unnecessary files. docker history shows layer sizes but not contents. Dive opens each layer in a file browser, showing the full filesystem diff. You can identify a 500MB layer caused by a package cache that should have been cleaned in the same RUN instruction.
How to use
- Install Dive via brew, apt, or download the binary.
- Run
dive <image>to analyze any Docker image. - Navigate layers with arrow keys and inspect the file tree to find optimization opportunities.
Example
# Install Dive
brew install dive # macOS
curl -OL https://github.com/wagoodman/dive/releases/download/v0.12.0/dive_0.12.0_linux_amd64.deb
sudo dpkg -i dive_0.12.0_linux_amd64.deb # Linux
# Analyze an image
dive nginx:latest
# Analyze a locally built image
docker build -t myapp .
dive myapp
# CI mode: fail if efficiency is below threshold
CI=true dive myapp --highestWastedBytes 50MB
Related on TokRepo
- AI Tools for DevOps -- Docker and container optimization tools
- AI Tools for Self-Hosted -- Self-hosted infrastructure tooling
Common pitfalls
- Dive reads the image from the Docker daemon. If the image is only in a remote registry, pull it first with
docker pullbefore running Dive. - Multi-stage builds can confuse the layer view. Dive shows all layers from the final stage. Intermediate stages are not visible unless you analyze them separately.
- The CI mode flag
--highestWastedBytesuses string values like '50MB'. Passing a raw number without units causes Dive to misinterpret the threshold.
Before adopting this tool, evaluate whether it fits your team's existing workflow. Read the official documentation thoroughly, and start with a small proof-of-concept rather than a full migration. Community forums, GitHub issues, and Stack Overflow are valuable resources when you encounter edge cases not covered in the documentation.
Frequently Asked Questions
Wasted space occurs when a file is added in one layer and deleted in a later layer. The file still exists in the earlier layer, consuming space in the final image. Dive detects these cases and reports the total wasted bytes.
Yes. Set CI=true and Dive returns a non-zero exit code if the image exceeds your configured thresholds for wasted space or efficiency score. This lets you gate deployments on image quality.
No. Dive is read-only. It analyzes image layers and displays their contents but never modifies the image. It is safe to run on production images.
Dive works with Docker and Podman. It reads images from the local container daemon. For Podman, use the --source podman flag.
Combine RUN instructions to avoid intermediate files persisting across layers. Clean package caches in the same RUN step that installs packages. Use multi-stage builds to exclude build tools from the final image. Dive shows exactly which layers to target.
Citations (3)
- Dive GitHub— Dive explores Docker image layers and identifies wasted space
- Dive README— CI mode with efficiency thresholds
- Docker Documentation— Docker image layer structure
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.