Docker - basics to Advance Part 1
Embarking on a journey into the world of containers and virtualization with Docker! In this blog, we'll explore the fascinating realm of containerization and how it's revolutionizing application deployment.
Container : A container is a standard unit of software that packages up code and all its dependencies, ensuring that an application can run quickly and reliably across different computing environments.
A Docker container image is a lightweight, standalone, executable package of software that encompasses everything required to run an application: code, runtime, system tools, system libraries, and settings.
Containers VS Virtual machine
Containers and virtual machines serve the purpose of isolating applications and their dependencies, but they exhibit distinct differences:
Resource Utilization: Containers are lighter and faster than virtual machines (VMs) since they share the host OS kernel. VMs require a full-fledged OS and hypervisor, leading to higher resource consumption.
Portability: Containers are inherently portable and can execute on any system with a compatible host OS. VMs are less portable as they necessitate a compatible hypervisor for operation.
Security: VMs offer heightened security as each VM operates with its dedicated OS, ensuring isolation from the host and other VMs. Containers provide comparatively less isolation by sharing the host OS.
Management: Container management is generally simpler compared to VM management due to its lightweight and agile nature.
Docker : An open-source, centralized platform to create, deploy, and run applications, it employs host OS containers for application execution. Docker enables applications to share the host computer's Linux kernel, sidestepping the need for an entire virtual OS.
While Docker can be installed on any OS, its engine operates natively on Linux distributions. It serves as a tool for OS-level virtualization, referred to as centralization.
Before Docker's emergence, users frequently encountered issues where code was executed on developers' systems but not on users' setups.
Why Docker?
Docker addresses dependency issues seamlessly. If it's built on your system, it can be built anywhere.
Instantly create multiple environments for production, quality assurance, testing tools, and more.
Implement reliable Continuous Integration (CI) with ease.
The container image is an executable encompassing all files and dependencies needed for application execution. This means creating an environment is as straightforward as running an executable file.
Though images can be larger, they are compartmentalized into layers.
Changes are updated by uploading only the altered layers.
Costs are trimmed by optimizing disk, network, and memory usage.
Advantages of Docker :
No Pre-allocation of RAM
Efficient CI: Docker allows you to create a container image and employ the same image throughout all deployment stages.
Cost Savings
Lightweight: Docker has a small footprint.
Versatile Deployment: It functions on physical, virtual, and cloud-based hardware.
Image Reusability
Swift Container Creation: Docker facilitates rapid container instantiation.
Disadvantages of Docker :
Limited GUI Support: Docker is not ideal for applications that heavily rely on a rich graphical user interface (GUI).
Managing Large Containers: Managing a large number of containers can become complex and challenging.
OS Compatibility: Docker is most suitable when the development and testing operating systems are the same. If the OS is different, virtual machines (VMs) might be a better choice.
Docker Architecture :
Docker employs a client-server architecture. The Docker client communicates with the Docker daemon, responsible for the essential tasks of constructing, executing, and disseminating your Docker containers. The Docker client and daemon can function on the same system, or a Docker client can link to a remote Docker daemon. Interaction between the Docker client and daemon transpires via a REST API, either through UNIX sockets or a network interface. An additional Docker client is Docker Compose, designed for managing applications comprising multiple containers.
Components of Docker :
Docker Daemon :- The Docker daemon operates on the host OS. It oversees container execution and manages Docker services. It can establish communication with other daemons.
Docker Client :-
The Docker client enables users to engage with the Docker daemon through a command-line interface (CLI).
It employs commands and a REST API to establish communication with the Docker daemon.
Whenever a user executes a server command in the Docker client terminal, the client terminal transmits these Docker commands to the Docker daemon.
A Docker client can interact with multiple daemons simultaneously.
Docker Host :- The Docker host serves as an environment for executing and running applications. Within the Docker host, several key components are present, including the Docker daemon, images, containers, networks, and storage mechanisms.
Docker Hub/Registry :- A Docker registry plays a pivotal role in managing and storing Docker images.
In the Docker ecosystem, two distinct types of registries exist:
Public Registry :- Commonly referred to as Docker Hub, this registry serves as a platform for sharing and accessing Docker images across a wide user base.
Private Registry :- Used primarily within an enterprise setting, a private registry facilitates the internal sharing of Docker images among authorized users.
Docker images :- Docker images are immutable binary templates utilized to generate Docker containers. These images are in a read-only state and serve as the foundation for creating and running containers within the Docker environment.
Alternatively:
Docker images :- A Docker image can be visualized as a singular file that consolidates all the necessary dependencies and configurations needed to execute a containerized program.
Ways to create an Images :-
There are several methods to generate a Docker image:-
Retrieve from Docker Hub :- Obtain an image directly from Docker Hub, a repository housing a plethora of pre-built images shared by the community.
Build from Dockerfile :- Craft a Docker image from scratch by defining a Dockerfile—a text file containing instructions for assembling the image's components.
Derive from Existing Container :- Generate an image by modifying an existing container. The alterations made in the container can be captured as a new image.
Each approach offers a distinct way to create and customize Docker images, catering to various deployment requirements and scenarios.
Docker Container :- Container holds the entire package that is needed to run the application.
Images become containers when they run on the docker engine.
Check Part 2 - Click here
In Part 2 we will see How to install docker , some docker commands and dockerfile.
Subscribe to my newsletter
Read articles from Md Ahtesham directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Md Ahtesham
Md Ahtesham
As an AWS Certified Cloud Practitioner and DevOps Engineer, being 2.7 years of expertise in CI/CD implementation. I've developed automated pipelines using Jenkins, Git, Ansible, SonarQube, JFrog, resulting in reduced deployment time. Proficient in writing Ansible playbooks and managing infrastructure with Terraform. Leveraged Git/ GitHub for version control best practices and optimized branching/merging strategies. Seeking new opportunities to apply skills in enhancing collaboration and scalability while ensuring reliable deployments.