How can you see what is making up the size of a Docker image?
docker history lists every layer with its command and size. For file-level detail, the open-source tool dive shows what each layer adds or wastes, which helps you spot big leftovers.
Explain it simply
Opening a heavy suitcase to see which items weigh the most. docker history is the packing list with a weight beside each line. dive is opening each pocket and showing the actual items inside.
docker history --no-trunc myapp prints one row per instruction, with the size it added, so you immediately see that COPY . . added 400 MB because test data was inside the folder. dive myapp is an interactive terminal tool: the left panel lists layers, the right panel shows the file tree changes, and it reports an 'image efficiency' score and wasted space from files added then deleted. docker image inspect gives the layer hashes and total size.
This is the standard way to answer 'why is my image so big?' with evidence.
Example
docker history myapp
docker history --no-trunc --format '{{.Size}}\t{{.CreatedBy}}' myapp
dive myapp
docker image inspect myapp -f '{{.Size}}'What to say in the interview
"docker history shows each layer's instruction and size, and dive explores the file changes per layer and highlights wasted space. I use them to find the layer that is bloating the image before trying fixes."
Common mistakes
- Assuming the biggest FROM is the problem when a COPY layer is the real cause.