Docker Architecture
What is Docker ?
A platform for building running and shipping app in a consistent manner
Why do we need Docker?
Developers usually face “Its works on my machine” problem it may be due to
- One or more files missing
- Software version mismatch
- Different configuration settings
We can easily package an application with all its dependencies with Docker and run it on any machine with Docker installed. If our application needs .net core 6 , Mongo 5.0 we can make [.net core 6,0 , Mongo 5.0 , Our App] as a package and run it on any machine with Docker . If it works on a development machine it will work on any machines. Also if someone is new to the team they don't need to spend time configuring the system. They can just reuse the package. Using docker they can download app with the package and can run in isolated environment
Also this isolated environment allows different versions of software to run side by side.
One more advantage is we can also remove the application and its dependencies in one go. Since the application and all its dependencies run in an isolated environment we can easily remove the application without disturbing other applications in the system.
The isolated environment for running an application is called Containers.
How Containers differ from Virtual Machines ?
The key differentiator between containers and virtual machines is that virtual machines virtualize an entire machine down to the hardware layers and containers only virtualize software layers above the operating system level.
Each Virtual machine needs a full blown operating system. Since it encompasses the full OS it is slow to start and resource intensive.
On the other hand containers are lightweight and only include high level software, they are very fast to start and they need less hardware resources. Containers share the host systems kernel with other containers. This makes containers lightweight.
Docker Architecture
Docker's architecture uses a client-server model. It consists of the Docker Client, Docker Host, Network and Storage components, and Docker Registry / Hub. Let's take a look at each of these components individually.
Docker client
The Docker client enables users to interact with Docker. The Docker client can reside on the same host as the daemon or connect to a daemon on a remote host. A docker client can communicate with more than one daemon. The Docker client provides a command line interface (CLI) that allows you to issue build, run, and stop application commands to a Docker daemon. A Docker client's main purpose is to allow you to pull images from a registry and run them on Docker hosts.
DockerHost
The Docker host provides a complete environment to execute and run applications. It comprises of the Docker daemon, Images, Containers, Networks, and Storage
Docker Daemon
A persistent background process that manages Docker images, containers, networks, and storage volumes. The Docker daemon constantly listens for Docker API requests and processes them.
Docker Containers
Containers are encapsulated environments in which you run applications. The container can access only the resources defined in the image, unless additional access is defined when building the image into a container. Because containers are much smaller than VMs, they can be spun up in a matter of seconds, resulting in far better server density.
Docker Image
This image contains everything an application needs to run Image contains
- A cut down OS
- A Runtime environment
- Application files
- Third party library
- Environment variable
Once we have an image we can tell docker to start a container using that image
Docker registry
Once we can have an image we can push it to the docker registry like docker hub Docker hub to docker is github to git. Storage for docker images that anyone can use Since all the instructions to build the images of the application are written in the docker file with that we can package the application and run it anywhere