An image is an ordered list of layers, where each layer is an operation used to set up the image and container. These operations may include setting/updating system configuration, environment variables, installation of libraries or programs, and so on. These operations are specified inside a Dockerfile. Therefore, every layer corresponds to an instruction in the image’s Dockerfile.
For instance, if we are to generate a Docker image for our backend API, we need it to have the Node ecosystem installed, have our application code copied over, and our application built using yarn. Therefore, our image may have the following layers (lower layers are run first):
- Run yarn run build
- Copy application code inside the image
- Install a specific version of Node and yarn
- [Using a base Ubuntu image]
Each of these operations produces a layer, which can be viewed as a snapshot of the image at this point of the setup process. The next layer depends on the previous layer.
In the end, you get an ordered list of sequentially-dependent layers, which makes up the final image. This final image can then be used as a base layer for another image—an image is simply a set of sequential, dependent, read-only layers.