Docker Image Layer Analyzer
Operator: Abdulla Al Fahad. How tools are built and checked
A container image is a stack of layers, and a file that one layer deletes is still stored in the layer that added it. That is why a Dockerfile that downloads an archive, unpacks it and removes it in a later RUN step ships the archive anyway. This page replays an image's layers one after another, applies the whiteout markers that stand for deletions, and shows what each layer added, changed and removed and how many bytes later layers made pointless.
It reads a docker save tarball or an OCI image layout, streaming each layer through its decompressor rather than loading it, and it also lists installed packages and scans configuration-style text files for secrets, which are shown masked.
Key features
- Layer table with the Dockerfile command from the image history, compression format, compressed size, content size, file counts, and added, changed and deleted counts
- Per-layer change list with path filter and status filter, including entries removed by whiteout files and by opaque directories
- Wasted-space table and an efficiency percentage (file bytes in earlier layers that a later layer overwrote or deleted, as a share of all file bytes), and the largest files in the final filesystem with the layer that supplied them
- Secret candidates found by the secret-scanner rules in .env files, key files, config directories and the image's own ENV and build commands, masked in the page and in exports, with credentials on build command lines hidden in the layer table and the CSV and JSON
- Installed packages from dpkg, apk or an rpm SQLite database, and JSON and CSV exports
How layers are replayed and how wasted space is counted
A docker save tarball has a manifest.json that lists the config file and the layer files in order; newer Docker versions also write an OCI layout (index.json and blobs/sha256/…) inside the same tar. An OCI folder is read from index.json through the manifest blob, including image indexes that list one manifest per platform. Layers are told apart by their first bytes: 1F 8B for gzip, 28 B5 2F FD for zstd, anything else as plain tar.
A deletion in a layer is a zero-byte file named .wh.<name> next to where the file was; a file named .wh..wh..opq in a directory hides everything the lower layers put in that directory. The analyzer applies both to the state built from lower layers before adding the layer's own entries. Wasted bytes are file sizes taken from tar headers. Hard links and symlinks count as zero bytes, because their data lives elsewhere.
Limits: the layers may inflate to 3 GB each and 4 GB in all, counted from the bytes that actually come out of the decompressor. Two checks stop a bomb earlier than that: a tar header that declares more than 3 GB of file data ends the read at once, and a gzip or zstd layer that has inflated past 256 MB at more than 150 times its compressed size is refused. At most 600,000 entries per layer and 1.5 million in all are read, tar extended headers are limited to 1 MB, and secret scanning reads at most 96 MB of text files of up to 256 KB each. Package databases are read up to 16 MB, and an rpm SQLite database up to 64 MB.
How it works
Secret scanning is selective. Candidates are files with a known sensitive name (.env, id_rsa, .npmrc, credentials, *.pem and similar) and text files under directories such as /app, /etc, /home, /root, /opt and /srv, minus folders like node_modules, site-packages and /usr/share. Each candidate is read once while the layer streams past and scanned immediately, so no file is kept after it has been scanned.
A .env file (or .env.production and the like, but not .env.example) at any path is listed as a finding for its presence alone, and every KEY=value line in it whose name looks sensitive (password, secret, token, key and similar) is listed with the value masked, even when the value is short or looks like documentation. The same presence finding covers id_rsa, .npmrc, .netrc, kubeconfig and the other known credential names. Build commands from the image history are masked before they reach the table or any export: values after -u user:pass, --password, --token, Authorization headers, user:password@ in URLs and name=value pairs with a sensitive name become ********.
When this helps
- A developer's Node image is 1.1 GB. The Wasted space tab shows a 380 MB build cache directory added in layer 4 and removed in layer 5, so a multi-stage build would save the whole amount.
- A platform engineer scanning images before promotion finds an id_rsa file in layer 3 that a later layer deleted. It is gone from the running container but still sits in the layer, so the image has to be rebuilt and the key rotated.
- A team debugging why pulls are slow sees that layer 2 is 410 MB compressed because package updates ran before and after a COPY step, so every code change re-ships the updates.
Opening a file
- Drop the .tar from docker save (or docker image save), pick an OCI layout folder, or try the built-in image.
- Read the Layers table and select a layer to list its changes.
- Open Wasted space to see which files cost the most, and Secrets for masked findings.
- Export the JSON report or CSV tables.
Example
A made-up three-layer Alpine-style image with 1,904,751 bytes of file content across layers (the built-in example)
Layer 1: base files, a 900,000-byte busybox and a 400,000-byte libssl
Layer 2: COPY app /app with server.js, a 600,000-byte data.bin and an .env file
Layer 3: RUN rm /app/data.bin and a patched /etc/os-releaseLayers, Wasted space and Secrets tabs
Layer 3: 1 file deleted, 1 changed, 600,053 bytes wasted (data.bin 600,000 and the old os-release 53)
Efficiency 68.50%; final image 6 files, 1,304,698 bytes; packages: 3 (apk)
Secrets: app/.env flagged in layer 2 as a credential-style file, with an aws-access-key-id and an aws-secret-access-key found inside it, all shown maskedTips for best results
- Read the command column next to the wasted bytes: the layer that made bytes pointless is shown, not the one that stored them, so it is the RUN step you need to rewrite.
- Use the path filter with status Deleted on a late layer to see exactly what a cleanup step removed; anything listed there is dead weight in an earlier layer.
- For multi-platform images in an OCI layout, pick the platform in the image selector first; each platform has its own layers.
Limits
The efficiency figure counts file bytes from tar headers, which is not the same as compressed pull size. A well-compressed file can be a large share of the efficiency loss and a small share of the download.
A secret that was deleted in a later layer is still reported, which is deliberate: it is still in the image. A secret that is not found is not proof of none, because only common locations and file names are scanned.
Vulnerabilities are not checked. The package list is an inventory to give to a scanner that has a CVE database.
Older rpm databases (Berkeley DB and NDB formats) are not read, so images built on them list no packages here.
Common errors and how to fix them
- No image was found: the archive has neither a manifest.json nor an index.json
- The tar is not an image export. Create one with docker save -o image.tar name:tag, or point the folder picker at an OCI layout that contains index.json.
- Layer 3 inflates to more than 3 GB, so reading stopped
- The compressed layer expands far beyond its size, which is how decompression bombs look. If the layer is genuine, analyse a smaller image or split the content over several layers.
Best practices
- Pass credentials to a build as a secret mount instead of a RUN argument or ENV: this page masks command lines in what it shows and exports, but the image history itself still holds them for anyone who runs docker history.
- When the Secrets tab lists a .env file in an early layer, rotate what is in it even if a later layer deleted the file; the layer that added it is still part of the image.
Frequently asked questions
How exact are the file counts and byte totals?
They are read from tar headers, so they are exact for what the layers store. For an image whose layers hold 3,182 bytes of file data, 1,600 of them overwritten or deleted later, efficiency comes out at 49.72%, which is 1 - 1600/3182 worked by hand. The tally applies the whiteout rules described above, so it shows the arithmetic is right; whether a particular Dockerfile should avoid those bytes is for you to judge.
How does the efficiency score relate to dive's?
Both measure how much of what the layers store is not part of the final filesystem. Here efficiency is one minus the wasted bytes divided by all file bytes in all layers, and wasted bytes are earlier-layer sizes of files that were overwritten or deleted. The dive tool uses its own bookkeeping, so expect the same ranking of problems rather than identical percentages.
Why does a deleted file appear under Wasted space and not under Largest files?
Largest files lists what is in the final image. A file removed by a whiteout is not there, but its bytes stay in the layer that added it, so it is counted as wasted and attributed to the layer that deleted it.
Are rpm databases from real images supported?
Recent images that store packages in rpmdb.sqlite are read through the Packages table's header blobs, taking name, version, release, architecture and size. Databases in the older Berkeley DB or NDB formats are not read, so if the package list is empty or odd, cross-check it with rpm -qa inside the image.