# 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. ## Install Save in your project root: # Dive — Explore Docker Image Layers and Optimize Size ## Quick Use ```bash # Install Dive # macOS brew install dive # Linux curl -OL https://github.com/wagoodman/dive/releases/latest/download/dive_linux_amd64.deb sudo dpkg -i dive_linux_amd64.deb # Analyze an image dive nginx:latest # Build and analyze in one step dive build -t my-app . # CI mode (non-interactive, returns pass/fail) CI=true dive my-app:latest ``` ## Introduction Dive provides an interactive terminal UI for exploring the contents of a Docker image, showing you exactly what files each layer adds, modifies, or removes. Most developers have no idea why their Docker images are so large — Dive reveals the answer layer by layer. With over 54,000 GitHub stars, Dive has become the standard tool for Docker image analysis. It helps developers reduce image sizes (often by 50-80%), improve build cache efficiency, and understand the impact of each Dockerfile instruction. ## What Dive Does Dive reads a Docker image and presents two side-by-side views: the layer list (showing each Dockerfile instruction and its size) and a file tree (showing the filesystem at any layer). It highlights added, modified, and removed files, calculates wasted space, and provides an efficiency score. ## Architecture Overview ``` [Docker Image] | [Dive Analysis Engine] Reads image manifest and layer tarballs | +-------+-------+ | | [Layer View] [File Tree View] Each layer with Each layer's size, command filesystem and efficiency with changes | [Interactive TUI] Navigate layers Browse files See what changed | [Efficiency Report] Wasted space Image score Optimization hints ``` ## Self-Hosting & Configuration ```bash # Analyze any Docker image dive python:3.12-slim dive node:20-alpine dive my-registry.com/my-app:v2.1 # Build and dive in one command dive build -t my-optimized-app:latest . # CI integration (.dive-ci config) cat > .dive-ci << EOF rules: lowestEfficiency: 0.95 highestWastedBytes: 20MB highestUserWastedPercent: 0.10 EOF # Run in CI mode CI=true dive my-app:latest --ci-config .dive-ci # Exit code 0 = pass, 1 = fail # Use with Docker Compose CI=true dive $(docker compose images -q web) ``` ## Key Features - **Layer Explorer** — see exactly what each Dockerfile instruction adds - **File Tree** — browse the filesystem at any layer - **Change Detection** — highlights added, modified, and removed files - **Wasted Space** — identifies duplicate files across layers - **Efficiency Score** — rates your image optimization (0-100%) - **CI Integration** — fail builds if image efficiency drops below threshold - **Build Integration** — dive build combines docker build + analysis - **Multiple Sources** — supports Docker, Podman, and exported tar files ## Comparison with Similar Tools | Feature | Dive | docker history | Slim.AI | DockerSlim | |---|---|---|---|---| | Interactive UI | Yes (TUI) | No (text) | Yes (web) | No | | File Browser | Yes | No | Yes | No | | Wasted Space | Yes | No | Yes | Auto-remove | | CI Mode | Yes | No | Yes | Yes | | Auto-Optimize | No | No | No | Yes (minify) | | Cost | Free | Free | Freemium | Free | | Best For | Analysis | Quick check | Teams | Auto-slim | ## FAQ **Q: How do I navigate the Dive interface?** A: Tab switches between layer and file views. Arrow keys navigate. Space expands directories. Ctrl+A shows only added files. Ctrl+R shows only removed files. **Q: What is a good efficiency score?** A: 95%+ is excellent. 90-95% is good. Below 90% means significant wasted space — usually from files added and then deleted in later layers (use multi-stage builds to fix this). **Q: How do I reduce my Docker image size?** A: Use Dive to find large or unnecessary files, then: use multi-stage builds, start from slim/alpine base images, combine RUN commands to reduce layers, and add a .dockerignore file. **Q: Can Dive analyze Podman images?** A: Yes. Set the DIVE_SOURCE environment variable to podman, or use the --source flag: "dive --source podman my-image:latest". ## Sources - GitHub: https://github.com/wagoodman/dive - Created by Alex Goodman - License: MIT --- Source: https://tokrepo.com/en/workflows/00882c6d-371c-11f1-9bc6-00163e2b0d79 Author: AI Open Source