docker-analyzer

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT

README ΒΆ

DISA - Docker Image Size Analyzer

Go Version CI Docker Go Report Card

A powerful CLI tool that analyzes Docker images to help developers understand and optimize their image sizes.

Demo

Features

  • πŸ“Š Layer Analysis - Break down Docker images layer by layer with cumulative size calculations
  • πŸ” Space Breakdown - Identify what's consuming space (file types, directories, wasted space)
  • πŸ’‘ Optimization Suggestions - Get actionable recommendations for multi-stage builds, smaller base images, and cache cleanup
  • πŸ“ˆ Multiple Output Formats - Terminal tables, JSON for CI/CD, and shareable HTML reports
  • ⚑ Fast & Lightweight - Written in Go for maximum performance
  • 🐳 Native Docker Integration - Works with local images and remote registries
  • πŸ”„ Image Comparison - Compare two images side-by-side to see differences

Installation

macOS / Linux
Homebrew
brew tap firasmosbehi/tap
brew install disa
Shell Script
curl -sSL https://raw.githubusercontent.com/firasmosbehi/docker-analyzer/main/install.sh | bash
Manual

Download the latest release for your platform:

# macOS ARM64 (M1/M2)
curl -sSL https://github.com/firasmosbehi/docker-analyzer/releases/latest/download/disa_Darwin_arm64.tar.gz | tar xz
sudo mv disa /usr/local/bin/

# macOS AMD64 (Intel)
curl -sSL https://github.com/firasmosbehi/docker-analyzer/releases/latest/download/disa_Darwin_x86_64.tar.gz | tar xz
sudo mv disa /usr/local/bin/

# Linux AMD64
curl -sSL https://github.com/firasmosbehi/docker-analyzer/releases/latest/download/disa_Linux_x86_64.tar.gz | tar xz
sudo mv disa /usr/local/bin/

# Linux ARM64
curl -sSL https://github.com/firasmosbehi/docker-analyzer/releases/latest/download/disa_Linux_arm64.tar.gz | tar xz
sudo mv disa /usr/local/bin/
Windows
Scoop
scoop bucket add disa https://github.com/firasmosbehi/scoop-bucket
scoop install disa
Manual

Download the latest Windows release and extract to a directory in your PATH.

Docker
docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  ghcr.io/firasmosbehi/docker-analyzer:latest \
  analyze alpine:latest

Or create an alias:

alias disa='docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/firasmosbehi/docker-analyzer:latest'
disa analyze alpine:latest
Go Install
go install github.com/firasmosbehi/docker-analyzer/cmd/disa@latest

Quick Start

# Analyze an image
disa analyze alpine:latest

# Show optimization suggestions
disa analyze python:3.11 --suggest

# Show top 10 largest layers
disa layers node:18 --top 10

# Export as JSON
disa analyze myapp:latest --json --output report.json

# Generate HTML report
disa analyze myapp:latest --html --output report.html

# Compare two images
disa compare alpine:3.17 alpine:3.18

Example Output

Analysis Report
$ disa analyze python:3.11 --suggest

πŸ” Docker Image Analysis
═══════════════════════════════════════════════════════════
Image: python:3.11

πŸ“Š SUMMARY
───────────────────────────────────────────────────────────
Total Size:    379.8 MB
Layers:        13
Architecture:  linux/arm64

πŸ“¦ LAYERS (Top 5)
───────────────────────────────────────────────────────────
#    COMMAND                                     SIZE      CUMULATIVE
────────────────────────────────────────────────────────────────────
4    RUN apt-get install build-essential...      647.4 MB  1.0 GB
3    RUN apt-get install git mercurial...        198.8 MB  408.1 MB
1    ADD rootfs.tar.xz /                         148.6 MB  148.6 MB
11   RUN wget -O python.tar.xz...                69.6 MB   1.1 GB
2    RUN apt-get install ca-certificates...      60.7 MB   209.4 MB

⚑ EFFICIENCY
───────────────────────────────────────────────────────────
Efficiency Score:   69/100
Wasted Space:       996.0 MB

πŸ’‘ OPTIMIZATION SUGGESTIONS
───────────────────────────────────────────────────────────
[HIGH] Clean up package manager caches
       Estimated savings: ~250 MB
       
       RUN apt-get update && apt-get install -y <packages> \\
           && rm -rf /var/lib/apt/lists/*

[MEDIUM] Use python:3.11-slim base image
       Estimated savings: ~126 MB
       
       FROM python:3.11-slim
Image Comparison
$ disa compare alpine:3.17 alpine:3.18

πŸ” Docker Image Comparison
═══════════════════════════════════════════════════════════

πŸ“Š SUMMARY
───────────────────────────────────────────────────────────
Image 1:         alpine:3.17 | 3.1 MB
Image 2:         alpine:3.18 | 3.2 MB
Size Difference: +65.9 KB    | 2.1%
Common Layers:   1
Added Layers:    1
Removed Layers:  1

πŸ“¦ LAYER COMPARISON
───────────────────────────────────────────────────────────
TYPE | COMMAND                        | SIZE 1  | SIZE 2  | DIFF
─────┼────────────────────────────────┼─────────┼─────────┼──────────
  -  | ADD alpine-minirootfs-3.17...  | 7.7 MB  | 0 B     | -7.7 MB
  =  | CMD ["/bin/sh"]                | 0 B     | 0 B     | =
  +  | ADD alpine-minirootfs-3.18...  | 0 B     | 8.0 MB  | +8.0 MB

Commands

Command Description
disa analyze <image> Analyze a Docker image and show layer breakdown
disa analyze <image> --suggest Include optimization suggestions
disa analyze <image> --json Output as JSON
disa analyze <image> --html Generate HTML report
disa layers <image> Show detailed layer information
disa compare <img1> <img2> Compare two images side by side
disa version Show version information

Flags

Flag Description
-s, --suggest Show optimization suggestions
-j, --json Output as JSON
-H, --html Generate HTML report
-o, --output Output file path
-t, --top Show top N layers (default: 10)
-v, --verbose Enable verbose output
--no-color Disable colored output

Optimization Rules

DISA checks for common optimization opportunities:

Rule Description Priority
Base Image Size Suggest smaller alternatives (alpine, slim, distroless) High
Package Cache Cleanup Find apt, pip, npm, etc. caches not cleaned High
Multi-stage Builds Detect compiled languages that benefit from multi-stage High
Layer Consolidation Multiple RUN commands that could be combined Low
.dockerignore Suggest .dockerignore improvements Medium

CI/CD Integration

GitHub Actions
name: Docker Analysis
on: [push, pull_request]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install DISA
        run: |
          curl -sSL https://github.com/firasmosbehi/docker-analyzer/releases/latest/download/disa_Linux_x86_64.tar.gz | tar xz
          sudo mv disa /usr/local/bin/
      
      - name: Build image
        run: docker build -t myapp:latest .
      
      - name: Analyze image
        run: disa analyze myapp:latest --json --output disa-report.json
      
      - name: Upload report
        uses: actions/upload-artifact@v4
        with:
          name: disa-report
          path: disa-report.json
GitLab CI
analyze:
  image: ghcr.io/firasmosbehi/docker-analyzer:latest
  script:
    - disa analyze $CI_PROJECT_NAME:$CI_COMMIT_SHA --json > disa-report.json
  artifacts:
    reports:
      metrics: disa-report.json

Development

# Clone repository
git clone https://github.com/firasmosbehi/docker-analyzer.git
cd docker-analyzer

# Install dependencies
go mod download

# Build
go build -o bin/disa ./cmd/disa

# Run tests
make test

# Run linter
make lint

# Format code
make fmt

Requirements

  • Go 1.23+ (for building from source)
  • Docker Engine 20.10+ (for analyzing images)

Architecture

docker-analyzer/
β”œβ”€β”€ cmd/disa/              # CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ analyzer/          # Analysis orchestration
β”‚   β”œβ”€β”€ calculator/        # Size calculations
β”‚   β”œβ”€β”€ comparator/        # Image comparison
β”‚   β”œβ”€β”€ docker/            # Docker client wrapper
β”‚   β”œβ”€β”€ errors/            # Error types
β”‚   β”œβ”€β”€ models/            # Data structures
β”‚   β”œβ”€β”€ optimizer/         # Optimization rules
β”‚   β”œβ”€β”€ parser/            # Layer parsing
β”‚   β”œβ”€β”€ reporter/          # Output formatters
β”‚   └── version/           # Version info
└── docs/                  # Documentation

Contributing

Please read CONTRIBUTING.md for guidelines.

License

DISA is licensed under the MIT License.

Acknowledgments


Made with ❀️ by the DISA contributors

Directories ΒΆ

Path Synopsis
cmd
disa command
disa/commands
Package commands provides the CLI commands for the disa application.
Package commands provides the CLI commands for the disa application.
internal
analyzer
Package analyzer provides the main image analysis orchestration.
Package analyzer provides the main image analysis orchestration.
calculator
Package calculator provides size calculation and efficiency analysis.
Package calculator provides size calculation and efficiency analysis.
comparator
Package comparator provides image comparison functionality.
Package comparator provides image comparison functionality.
docker
Package docker provides Docker client functionality.
Package docker provides Docker client functionality.
errors
Package errors provides custom error types for the disa application.
Package errors provides custom error types for the disa application.
models
Package models provides data structures for Docker image analysis.
Package models provides data structures for Docker image analysis.
optimizer
Package optimizer provides optimization suggestion generation.
Package optimizer provides optimization suggestion generation.
parser
Package parser provides functionality to parse Docker image layers.
Package parser provides functionality to parse Docker image layers.
reporter
Package reporter provides HTML output formatting.
Package reporter provides HTML output formatting.
version
Package version provides version information for the application.
Package version provides version information for the application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL