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.
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.
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>
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,
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.