layer

One read-only slice of an image that records the files a single build step added, changed or deleted.

In more detail

Each Dockerfile instruction that changes files (RUN, COPY, ADD) produces a layer; instructions such as CMD only change metadata and add a history entry without a layer. Layers are stored and pulled by their digest, so layers shared between images are downloaded and stored once. Deleting a file in a later layer only hides it, so anything added to an earlier layer, including a secret, is still inside the image.

Examples

docker image inspect layers:demo -f '{{len .RootFS.Layers}}'
Copying package.json and the lockfile before the source reuses the install layer whenever only code changes.

Related terms

Taught in

References

Certification courses