*Author: [Vincent Lau](https://www.linkedin.com/in/vincent-lau-30435bb6/)
Note: This material is intended for educational purposes only. All rights reserved. Any unauthorized sharing or copying of this material, in any form, to any individual or party, for any use without prior permission, is strictly prohibited.*
# Docker Series - Dockerization
This chapter walks through the basic concepts of Docker, including the Docker Components, Architecture , how it works, and the benefits of adopting it as the part of application architecture.
## What is Docker ?

> Dockerizing is the process of packing, deploying, and running applications using Docker containers. - developerexperience.io
**Docker** is both a command-line tool and a platform that provides **an ecosystem for containerization**. It includes the Docker engine, which is the runtime responsible for building, running, and managing containers. Docker also provides a **command-line interface (CLI) and API that allow users to interact with Docker and manage container resources**.
When using Docker, you typically start by creating a **docker image**. An image is a read-only template that contains everything needed to run an application, **including the application's code, runtime environment, libraries, and dependencies**. Images are created using a **Dockerfile**, which is a text file that **specifies the steps to build the image**. Once you have an image, you can create one or more containers based on that image.
## What is Container ?

A **container** is a standalone and executable software unit that encapsulates an application along with all its dependencies, libraries, and configuration files. Containers are isolated from the underlying host system and from other containers, ensuring that applications run consistently across different environments. Containers are **lightweight** because they share the host system's kernel, making them faster to start and **requiring fewer resources compared to virtual machines**.
Containers can be managed and orchestrated using Docker's command-line interface, APIs, or container orchestration platforms like **Kubernetes**. Docker provides features for **networking, volume management, scaling, and container lifecycle management**, making it easier to work with containers and deploy applications.
## Docker Architecture

### Core Components in Docker Architecture
**Docker Client**: The Docker client is the primary interface through which users interact with Docker. It provides a command-line interface (CLI) and API that allow you to issue commands to the Docker engine. The Docker client communicates with the Docker daemon, which is the background service responsible for building, running, and managing containers. The Docker client can be installed on the same machine as the Docker daemon or on a remote machine to manage Docker resources remotely.
**Docker Images**: Docker images are the building blocks of containers. An image is a read-only template that contains all the necessary files, dependencies, libraries, and configurations needed to run an application. Images are created using a specification called a Dockerfile, which defines the steps to build the image. The Dockerfile includes instructions to copy files, install software packages, configure the environment, and more. Docker images are portable and can be shared and reused across different environments.
**Docker Registry**: Docker registry are repositories for storing and distributing Docker images. Registries act as central repositories where users can upload, download, and share Docker images. **Docker Hub** (hub.docker.com) is a popular public registry that hosts a vast collection of pre-built Docker images contributed by the community. You can search for images on Docker Hub and pull them to your local machine for use. Additionally, you can create your own private Docker registry to store custom images specific to your organization or project.
### Relationship among Docker Client, Registry, Image & Container
The Docker client interacts with the Docker daemon to manage containers and issue commands for various Docker operations, such as building, running, and stopping containers.
To create a container, the Docker client uses a Docker image as a base. Images can be pulled from Docker registries or built locally using a Dockerfile. Docker registries serve as repositories for storing and distributing Docker images. Users can push their custom images to a registry for sharing or pull existing images from the registry to their local machine.
## Why dockerize & containerize applications?

**Isolation**: Containers provide a high level of isolation, allowing applications to run independently without interference from other applications or the underlying host system. Each container has its own file system, network interfaces, and process space, providing a sandboxed environment.
**Portability**: Containers are designed to be portable. Once an application is containerized, it can run on any machine or cloud platform that supports Docker or container technology. Containers ensure that the application runs consistently, regardless of the underlying infrastructure.
**Dependency Management**: Containerization helps solve the challenge of managing application dependencies. With traditional deployment approaches, conflicts can arise when different applications require different versions of the same libraries. Containers encapsulate all the necessary dependencies within the container image, eliminating conflicts and making application deployment more reliable.
**Scalability**: Containerized applications can easily scale horizontally by running multiple instances of the same container across different machines or within a cluster. Container orchestration platforms like Kubernetes enable dynamic scaling and load balancing of containerized applications, ensuring efficient resource utilization.
**DevOps and Continuous Integration/Deployment (CI/CD)**: Containerization plays a crucial role in modern DevOps practices. By packaging applications into containers, development teams can create consistent development, testing, and production environments. Containers are also well-suited for CI/CD pipelines, where applications can be built, tested, and deployed automatically.
**Resource Efficiency**: Containers are lightweight and share the host system's kernel, resulting in efficient resource utilization. Multiple containers can run on the same host machine, isolating the applications while consuming minimal resources. This makes containers an efficient choice for deploying microservices architectures.