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
- image — A read-only package containing a program and everything it needs to run, used as the template for containers.
- writable layer — The thin layer on top of an image where a running container writes its changes.
- union filesystem — A filesystem that stacks several directories on top of each other and shows them as one.
- copy on write — A rule where a shared file is only copied at the moment someone changes it.
- build cache — Saved results of earlier build steps that a build tool, such as Docker, reuses when nothing a step depends on has changed.
- whiteout file — A marker in a higher layer that says a file from a lower layer has been deleted.
- lockfile — A file that records the exact version of every dependency, including transitive ones, so every install gets the same set.
- Dockerfile — A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.
- multi-stage build — A Dockerfile with several FROM stages, where later stages copy only what they need from earlier ones.
- secret — Any value that grants access, such as a password, access token or private key, and must be kept out of code and version control.
Taught in
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Why Containers: Bare Metal, Machines And Processes — Docker Architecture & Production Containers
- Union Filesystems, Images And Writable Layers — Docker Architecture & Production Containers
- Docker, OCI, The Engine And The CLI — Docker Architecture & Production Containers
- Pull And Inspect A Third Party Image — Docker Architecture & Production Containers
- Run, Stop, Restart And Remove A Container — Docker Architecture & Production Containers
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- FROM, WORKDIR, COPY And ADD — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- ARG, ENV, LABEL, EXPOSE And VOLUME — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Tags, Digests And Reproducible Image References — Docker Architecture & Production Containers
- Authenticate, Tag, Push And Pull From A Registry — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Scan, Patch And Inspect The Software Supply Chain — Docker Architecture & Production Containers
- Ephemeral Filesystems And Named Volumes — Docker Architecture & Production Containers
- Bind Mounts, Permissions And Backups — Docker Architecture & Production Containers
- Port Publishing, Localhost And Network Troubleshooting — Docker Architecture & Production Containers
- Environment, Secret Files And Runtime Restrictions — Docker Architecture & Production Containers
- Health Checks, Dependencies And Reliable Startup — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- Containerization Architecture: Multi-Stage Dockerfiles — Production Full-Stack Engineering
- Containerized Deployment: Multi-Stage Docker Builds — Next.js 15 & Modern App Router Architecture
- Why Secrets Leak — Application Security & Threat Modeling for Engineers
- Container Security: Minimal Bases And Non Root — Application Security & Threat Modeling for Engineers
- Image Scanning And Trivy — Application Security & Threat Modeling for Engineers
References
- Understanding image layers (Docker docs)
- OCI image layer filesystem changeset
- Docker docs: Multi-stage builds