liveBook · Manning

Image layer

As explained in Kubernetes in Action, Second Edition

A container image layer is an independently stored filesystem change that composes a container image and can be shared across images.

A container image is built from layers rather than stored as one indivisible filesystem. A layer can be reused by multiple images. Docker stores a shared layer once, and a host downloading another image needs to fetch only the layers it does not already have. section 2.1.2

Layers from a Dockerfile

Start with `FROM node:23-alpine`, then use `COPY app.js /app.js`, `COPY html/ /html`, and `ENTRYPOINT ["node", "app.js"]`. Docker builds on the base image layer by layer: the two COPY directives add files, and the ENTRYPOINT directive specifies the startup command. Run `docker history kiada:latest` to see the resulting layers, their sizes, and the directives that created them. The newest layers appear first. section 2.2.2

$ docker history kiada:latest
IMAGE         CREATED   CREATED BY                           SIZE
afeb94f9465c  13m ago   ENTRYPOINT ["node" "app.js"]         0B       #1
<missing>     13m ago   COPY html/ /html                     533kB    #1
<missing>     13m ago   COPY app.js /app.js                  2.9kB    #1
<missing>     17h ago   CMD ["node"]                         0B        #2
<missing>     17h ago   ENTRYPOINT ["docker-entrypoint.sh"]  0B        #2
<missing>     17h ago   COPY docker-entrypoint.sh /usr/l...  388B      #2
<missing>     17h ago   RUN /bin/sh -c set -ex   && save...  7.18MB    #2
<missing>     17h ago   ENV YARN_VERSION=1.22.22             0B        #2
<missing>     17h ago   RUN /bin/sh -c ARCH= OPENSSL_ARC...  143MB     #2
<missing>     17h ago   ENV NODE_VERSION=23.4.0                        #2
<missing>     17h ago   RUN /bin/sh -c groupadd --gid 10...  8.9kB     #2
<missing>     9d ago    # debian.sh --arch 'amd64' out/...   74.8MB    #2

Compare the file-adding COPY layers with the 0B ENTRYPOINT layer, then look below them for layers inherited from the base image. section 2.2.2

Sharing an image layer does not mean containers share their changes. Each container uses the image’s read-only layers beneath its own read/write layer. If an application changes a file from a read-only layer, copy-on-write places a copy in that container’s read/write layer and changes it there. Other containers continue to see their own filesystem state. section 2.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines layer sharing, traces layers through a Dockerfile build, and explains container writes through copy-on-write.
Examples
Uses a Node.js Dockerfile and `docker history kiada:latest` to show COPY, ENTRYPOINT, inherited layers, and their sizes.
What it assumes
Introduces images and containers before layers, then uses Dockerfile directives and CLI commands in a concrete build.
What you can do after
Diagnose/debug with it by using `docker history` to identify an image’s layers, sizes, and creating directives.
How it connects
Connects image layers to container images, Dockerfiles, base images, container filesystems, and copy-on-write.

Also explained in

Compare how 5 books explain image layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.