DISA - Docker Image Size Analyzer

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

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