Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Layer analysis inspects a container image one filesystem layer at a time, revealing deleted-but-recoverable secrets, unexplained binaries, and which base image introduced a flaw.

What Is Container Image Layer Analysis?
A container image is not a single filesystem. It is an ordered stack of read-only layers, each recording the changes made by one build instruction, combined at runtime by a union filesystem. Layer analysis is the practice of examining those layers individually rather than looking only at the assembled result, and it answers questions a vulnerability scan cannot: what was added, by which instruction, and what is still recoverable even though the final image appears not to contain it.
Layers are additive. Deleting a file in a later instruction does not remove it from the earlier layer; it records a whiteout entry that hides it from the merged view. The bytes remain, and anyone who can pull the image can extract them.
That turns a common build pattern into a credential leak. A Dockerfile that copies a private key, an .npmrc, a cloud credentials file, or an entire .git directory into the image, uses it, and then removes it in a subsequent RUN instruction has published that secret to every registry user. The same applies to a multi-stage build where someone copies the whole build context into the first stage, and to ARG values that end up recorded in the image history. Extracting them takes one command and no particular skill, which is why it is a standard step in any assessment of a container platform and why it belongs in the same conversation as cloud credential leakage.
The command line gets you surprisingly far: docker history --no-trunc shows the instruction behind each layer, docker save produces a tar archive you can unpack layer by layer, and a search for key material across the extracted directories finds most accidental secrets. The interactive tool dive is purpose-built for browsing layer contents and highlighting wasted space.
For automation, Syft generates a software bill of materials with layer attribution, Trivy and Grype match packages to vulnerabilities and report which layer introduced each one, and secret-scanning tools such as gitleaks can be pointed at extracted layers rather than only at repositories. Attributing a finding to a layer is what makes remediation efficient: if every critical vulnerability traces to the base image, the fix is one base image upgrade rather than fifty package updates.
.dockerignore that excludes .git, .env, key files, and local configuration, and review it when the repository layout changes.Layer analysis complements rather than replaces container image scanning. Scanning answers what is vulnerable; layer analysis answers where it came from and what else is in there. Run secret detection on extracted layers as a build gate, generate a software bill of materials per image and store it with the artefact, and keep the analysis output in your registry alongside the image, as discussed in container registry security.
One detail worth remembering: if a secret was ever in a published layer, rotate it. Rebuilding the image removes it from the new version only, and the old digest remains pullable by anyone who noted it.
At Privia Security, we inspect images and build pipelines as part of our cloud security services.
Yes. Container image layers are additive, and a deletion in a later instruction only writes a whiteout marker that hides the file from the merged filesystem. The original bytes remain in the earlier layer and can be extracted by anyone who pulls the image. Any secret that reached a published layer must be rotated, not merely removed from the next build.
Use multi-stage builds so that only the finished artefact is copied into the final stage, and use BuildKit secret mounts for credentials needed during the build, which are never persisted to a layer. Keep a thorough .dockerignore so local credential files and the .git directory never enter the build context at all. Then scan extracted layers in the pipeline to verify it worked.
No, they answer different questions. Scanning matches installed packages against vulnerability databases. Layer analysis shows which instruction and which base image introduced each component, surfaces secrets and unexplained binaries, and reveals bloat. Together they let you fix the common cause—usually a stale base image—rather than patching dozens of symptoms individually.
Check the base image and whether it is maintained, read the full build history for suspicious instructions, extract each layer and search for key material and configuration files, list binaries that no instruction explains, and inspect the image configuration for the user it runs as and any environment variables. If anything is unexplained, do not run it in a trusted environment.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.