Docker – Layered Architecture

Layered Architecture

Hello Everyone,

Hope you’re doing well. In previous article we converted our node project to dockerise one. We saw that while creating docker image, there were few set of instructions after each step. In this article we’ll understand what were those instructions. For other similar articles please refer index page.

Quick links :

Layered Architecture :

When we execute docker build command, We see some logs while executing each line from Dockerfile. Let’s have a quick look again, and analyse it.

Instructions of docker build command.
Instructions of docker build command

Docker Image contains several layers, each layer is created by respective Dockerfile instruction. There are only few instructions which is responsible for creating layers they are RUN, COPY and ADD. Other instructions creates intermediate layer and doesn’t contribute to the overall size of your Image. That’s why in above image we see removing intermediate container instructions. But why it say intermediate container and not intermediate layer ? That’s because all steps are executed in an intermediate container, once instruction is executed, container is deleted.

Each layer is readonly, it contains difference between previous layer and current layer. On top there’s a writable layer (current layer) which is called, the container layer.

I hope these concepts are clear, let’s execute a command,

docker history <image_id>

docker image command execution result.
docker image command execution result.

As we see in above image, each layer contributes to the overall size of the image. As expected few layers have 0B size, as those instructions doesn’t contribute to the size and they are the same layers who’s containers were removed.

There are some missing layers, they are the layers of base image. <missing> indicates that the base image was not build in local environment.

As we already know, if we execute docker build again, it will utilise the current available images. That’s why we see using cache in instruction.

Let’s have quick pictorial representation of our docker image,

Pictorial representation of docker image layers.
Pictorial representation of docker image layers.

I hope this clears your concepts of Docker’s Layered Architecture. We’ll learn few more details for the same in next article. For any queries / doubts please comment / get in touch with me. For other similar articles please refer index page.

Sanket Modi

Working in Information Technology since 2012. Started my career as Java Developer and now working in multiple different technologies like nodejs, Python, Docker, Kubernetes, Azure etc. I like to explore new technologies and read books.

You may also like...

1 Response

  1. February 11, 2021

    […] Layered Architecture […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: