Docker – Understanding Layers

In previous article we explored the basic concepts of docker images and now we will move forward to the building blocks of a docker image i,e. layers.

Layers are the building blocks of docker image, instructions like ADD, COPY and RUN are used to create layers within an image. Layers in an image can be reused.

Docker image layers
Docker image layers

Layers can also be called sub-images and using union filesystem docker will combine all these sub-images (layers) into a single image. Union file system allows overlaying of files and directories from different file systems.

Union Filesystem
Union Filesystem

Using Union Filesystem layers are arranged in a stack, every layer within an image is identified with a layer id and pointers are used to connect layers with each other. Every child layers in an image will have a pointer to it’s parent layer as shown in following diagram.

Docker image - layer pointers
Docker image – layer pointers

Docker keep track of all the files / layers using checksum, while building the image docker will check if an existing layer with matching checksum is available in cache, if yes it will reused instead of creating a new one. This concept of layer reusability makes docker a light weight solution to deploy, run and distribute applications.

Layers are additive in nature, this helps maintain complete history of an image and enables the possibility to rollback to a specific point in history of an image. Docker’s image tagging functionality is used to enable features like history and rollback, we will explore image tagging in upcoming article.

In this article I explained the basics of docker image layers, so now we know that docker images are actually composed of layers. Docker images will have read-only layers, on starting a container docker will use read-only layers of a base image and will add a writeable layer on top of it. In next article we will learn about docker containers.

Shoket Mahmood Ahmed

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top