<p>My understanding is that Docker creates an image layer at every stage of a dockerfile.</p>

<p>If I have X containers running on the same machine (where X >=2) and every container has a common underlying image layer (ie. debian), will docker keep only one copy of the base image on that machine, or does it have multiple copies for each container?</p>

<p>Is there a point this breaks down, or is it true for every layer in the dockerfile?</p>

<p>How does this work?</p>

<p>Does Kubernetes affect this in any way?</p>

<p>Dockers <a href="https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/" rel="noreferrer">Understand images, containers, and storage drivers</a> details most of this.</p>

<p>From Docker 1.10 onwards, all the layers that make up an image have an SHA256 secure content hash associated with them at build time. This hash is consistent across hosts and builds, as long as the content of the layer is the same. </p>

<p>If any number of images share a layer, only the 1 copy of that layer will be stored and used by all images on that instance of the Docker engine.</p>

<p>A tag like <code>debian</code> can refer to multiple SHA256 image hash's over time as new releases come out. Two images that are built with <code>FROM debian</code> don't necessarily share layers, only if the SHA256 hash's match. </p>

<p>Anything that runs the Docker Engine underneath will use this storage setup. </p>

<p>This sharing also works in the Docker Registry (>2.2 for the best results). If you were to push images with layers that already exist on that registry, the existing layers are skipped. Same with pulling layers to your local engine. </p>
