Image Size Audit
Intermediate10 min
Analyze Docker image layers to understand what is taking up space and identify optimization opportunities.
Prerequisites
- -Docker installed
Steps
1
List images sorted by size
See all images and their sizes, largest first.
$ docker images --format '{{.Size}}\t{{.Repository}}:{{.Tag}}' | sort -hr | head -20
2
Inspect image layer sizes
Break down an image into its constituent layers to see what each adds.
$ docker history myapp:latest --format 'table {{.Size}}\t{{.CreatedBy}}' --no-trunc
3
Use dive for interactive layer analysis
Run dive to explore each layer's filesystem changes interactively.
$ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive myapp:latest
Dive shows wasted space, efficiency scores, and lets you browse each layer's file tree.
4
Find dangling images consuming space
Identify untagged images that are using disk space.
$ docker images -f 'dangling=true' --format 'table {{.ID}}\t{{.Size}}\t{{.CreatedSince}}'
5
Check total Docker disk usage
See a summary of disk space used by images, containers, volumes, and build cache.
$ docker system df -v
Full Script
FAQ
Discussion
Loading comments...