Understanding Docker's Architecture

Have you ever come up with any bitter experience where a certain software works in your friend's machine, but not works in your machine? This is a very common situation where we come across. The applications need to prepare the required environment and fulfill the required prerequisites prior the process of running.

Sometimes a code you have developed may not work as you expected in another environment. This happens because you might be on a different operating system, say your machine is a Windows machine and you are going to push it out to a Linux server. Many problems arise when the environments are not the same. Docker solves this problem !

Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. It helps to deliver the applications fast. Docker separates applications from its infrastructure like a managed application. With Docker, we can ship code faster, test code faster and deploy code faster. This will shorten the cycle between writing the code and running the code.

With Docker, the applications run securely isolated in a container. Many containers can be run simultaneously as Docker provides isolation and security. The lightweight nature of containers allows to get more out of the hardware.

Docker allows developers to develop on local containers that contain the applications and services. It can then be integrated into a continuous integration and deployment workflow. The developers can share their development code with others. Then the code can be pushed onto a test environment. After that they can be pushed into production.

The process of deploying and scaling is more easy. Docker supports portable workloads as they can run on a developer's local host, on physical or virtual machines in a data center or in the Cloud. With Docker, applications and services can be quickly scaled up and down in near real time.

Major Docker components

There are two major Docker components.
                Docker: the open source container virtualization platform.
                Docker Hub: Software-as-a-Service platform for sharing and managing Docker containers.

Docker's architecture

Docker has a client server architecture as below.

Docker client talks to the Docker daemon. This communication happens via sockets or through a RESTful API. Docker client and the Docker Daemon can reside in the same system or a remote system.

Docker daemon 

Runs on a host machine. This does the job of building, running and distributing the Docker containers. User interacts with the Docker daemon through Docker client.

Docker client

This is the primary user interface to Docker. It accepts the commands from the user and communicates with the Docker daemon. For eg: If the user requires to run a docker image, the user enters the command 'docker run' along with the image name, so that the Docker client passes the message to the Docker daemon to execute the action. Docker daemon checks for the image locally on the host and if it doesn't exist, Docker downloads it from the Docker Hub registry.

Docker images

Docker image is a read only template. Docker image contains the installments that are required. The complete application is wrapped up in an image. These images are used to create Docker containers.

If a machine has Docker on it, we can run as many containers as we want from that Docker image. Say you want to run an image for a node.js application in your machine. This whole image, source code and all will run with a complete environment. You do not need to install node.js in your machine, because image has every thing. Everything you need to run a particular container is defined in its corresponding image. If Docker is installed, that's all you need.

Each image has a series of layers. Docker makes use of union file systems to combine theses layers into a single image. These layers make Docker lightweight. Suppose you upgrade an application to a new version by updating its image. Then a new layer gets built. Now you don't need to distribute a whole new image, just the update, making distributing Docker images faster and simpler.

Every image starts from a base image and every container uses the same base image. Docker images are built from these base images using a set of instructions which is stored in a file called Dockerfile. Dockerfile is usually a small file where each instruction in this file creates a new layer in the image. These instructions can include running a command, adding a file or directory, creating an environment variable etc. When you request a build of an image, Docker reads the Dockerfile and executes the instructions in order to return an image.

Docker image
Docker registry

This is where the Docker images are stored and shared. Registry include private as well as public repositories. Images can be uploaded or downloaded from Docker registry. Docker Hub which is like Git Hub is a public SaaS that provides the public Docker registry. We can use existing images from the registry, rebuild them and push them back to the registry so that others also can share it. Hence we can create our own images or use images that others have created.

Public repositories are searchable and can be downloaded by anyone. Private repositories are excluded from search results, because only you and your users can pull images down and use them to build containers.

Docker containers

A Docker container holds everything that is needed for an application to run. It might contain an operating system, user added files and meta data. How is a container created from an image? Image tells Docker what the container holds and what process to run when the container is launched along with some configuration data. When Docker runs a container from an image, it adds a red write layer on top of the image in which the specific application can then run. Docker containers can be started, run, stopped or deleted. Each container is an isolated and secure application platform. As I feel, a container is the run time representation of the image.

Underlying technology

Docker is written in a programming language called 'Go'.
Uses several Linux features.
  1. Namespaces : To provide isolation
  2. Control groups : To share and limit hardware resources
  3. Union file system : Makes it light and fast by layering
  4. libcontainer : Defines container format

    SUMMARY : 

    • Build component of Docker is Docker image.
    • Distribution component of Docker is Docker registry.
    • Run component of Docker is Docker container.


    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer Node js Training in Chennai . learn from or Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai