Image size, transfer and shared layers
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Before any separately authorized Docker query, verify the effective endpoint and builder (including environment overrides), not just the context name. Use only disposable lab resources; a failed check is a stop condition, not permission to retry against a different host.
Fictional layer accounting (MiB, ignoring metadata):image A: shared base=80, unique app=40 -> 120image B: same base=80, unique app=20 -> 100combined unique content=80+40+20=140, not 220registry compressed transfer for B: hypothetical 45 MiB with no blobs cachedStaged inspection: docker image ls; docker system df -vImage list size describes cumulative image content rather than the incremental local cost of another tag. Shared blobs and layers can avoid duplicate transfer or storage depending on the store. A registry manifest identifies compressed blob sizes for a selected platform, whereas local disk usage depends on unpacking, snapshots, metadata and caches. Treat docker system df as daemon accounting, not an exact physical disk census. Multi-stage builds can omit compilers and temporary files from final images; deleting files in a later layer does not erase their bytes in an earlier layer. Use a minimal compatible base, preserve required certificates and runtime libraries, and test startup, features, security and license obligations. Do not claim Alpine, distroless or scratch is always fastest; compare the same application contract and architecture. The three-image practice assumes each image has exactly one identical base and one disjoint unique layer. Its unique total is 122 MiB and the sum of image sizes is 242 MiB. A shared size in daemon accounting does not establish exact reclaimed space, compressed transfer bytes or snapshot disk allocation.
Common mistake
Do not sum image list rows to estimate reclaimable bytes. Shared layers, tags and other references change what is reclaimable.
Manual practice
For a 60 MiB common base and three unique layers of 12, 20 and 30 MiB, calculate total unique content and sum of image sizes. Explain why neither is a guaranteed physical disk measurement.
Worksheet: lab-fixtures/docker-performance-engineering/04-image-size/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Image size, transfer and shared layers — Knowledge check
Interpret performance evidence and make a safe operational decision.
How much unique layer content is in the original example?
Does deleting a file in a later layer erase its original layer bytes?
Which must be retained when choosing a small base?