Diving into Docker: Containerization Simplified

Diving into Docker: Containerization Simplified

containers are definitely a thing.

Why containers?

Applications run business and most applications run on servers. If applications break, the business has to suffer. In the early 2000s, every time a business needed a new application it had to buy a new server. A tragic waste of time and resources!

Amid all of this VMware Inc. introduced the virtual machine (a technology that lets us safely and securely run multiple applications on a single server.) but there is always a but, VMs are great but they are not perfect and the problem with VMs is that it requires its dedicated operating system and are too slow to boot and portability isn't great.

This led to the need for a technology that helps to run multiple applications on a single server without using multiple operating systems.

Hello, containers!

Containers help to package the software code with just the operating system (OS) libraries and only those dependencies required to run the code to create a single lightweight executable, that runs consistently on any computer this concept of packing required things is known as containerization.

The concept of containerization and process isolation is actually decades old, but the emergence in 2013 of the open-source Docker Engine—an industry standard for containers with simple developer tools and a universal packaging approach—accelerated the adoption of this technology.

Containers vs Virtual Machines

As discussed above containers and VMs both need a host(machine) to run on. 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.

Hypervisor: A program used to run and manage one or more virtual machines on a computer.

Container Engine: You will be learning about it below.

Let's learn about Docker now:

Docker!

Docker is an open source containerization tool that creates, manages, and orchestrates containers. It packages all the build dependencies required to run an application using a dockerfile that then creates a docker-image(blueprint of the container) that defines a docker-container( instance of an image).

Fun fact: Docker is an English word that means a person who loads and unloads containers on the ship. The reason why the docker logo has so many containers on the top of the fish.

let's understand some of the terms used above:

i.Orchestrating containers:

Container orchestration refers to the automated management, deployment(launch), scaling, and operation of containerized applications.

ii. Build dependencies:

Build dependencies are essential prerequisites, like libraries and tools, required to compile and build software projects it's like ingredients needed to bake a cake; you can't make the cake without prerequisites (flour, eggs, and sugar).

Architecture of Docker

Docker uses a client-server architecture, the Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers.

  • The Docker Client is a command-line interface (CLI) tool used by users to interact with Docker and it communicates with the Docker daemon using REST API to execute these commands.

  • Docker Daemon(dockerd) is the core background service running on the host system and is responsible for managing containers, images, networks, and volumes listens for Docker API requests, which can come from the Docker Client or other Docker tools.

  • A docker image is like a template that contains multiple layers that get stacked on top of each other and this layer contains everything that is needed to run a container and images are usually small in size.

  • A docker container is the run time instance of an image. A container is defined by its image as well as any configuration options you provide to it when you create or start it.

  • Registry: Registries are used to store images.

Docker Client:

The Docker client is a command-line tool or API that allows users to interact with the Docker daemon, which is responsible for managing containers on a host system.

Docker Engine:

Docker engine is a broader term which isolates and runs applications and their dependencies within lightweight, portable containers, enhancing software development, deployment, and scalability. It contains a Daemon responsible for handling container operations and containerd and runc to facilitate container execution and management.

Docker Daemon:

It is the core background service running on the host system and is responsible for managing containers, images, networks, and volumes listens for Docker API requests, which can come from the Docker Client or other Docker tools.The Docker daemon implements the Docker API which is currently a rich, versioned,HTTP API that has developed along side the rest of the Docker project.

Containerd:

It act as a bridge between the daemon and runc. It’s helpful to think of containerd as a container supervisor - the component that is responsible for container lifecycle operations such as; starting and stopping containers, pausing and un-pausing them, and destroying them.

Note: containerd was developed by Docker, Inc. and donated to the Cloud Native Computing Foundation (CNCF).

runc:

It has a single purpose in life - to create containers and we often refer runc as a container runtime.

Workflow:

Docker image:

Images are like templates or snapshots of applications and their dependencies or say ready-made packages for software. Analogically think of images as recipe cards that chefs follow to create delicious dishes. These images can be used to make multiple servings of the same program, just like chefs can use the same recipe to cook many meals.

Docker Container:

A container is the runtime instance of an image, following the analogy container is the meal. Images are considered buildtime constructs whereas containers are run-time constructs.

Registry:

Image registries contain multiple image repositories. In turn, image repositories can contain multiple images. In simple words, registries are used to store images.

The most common registry is Docker Hub (https://hub.docker.com). Other registries exist, including 3rd party registries and secure on-premises registries.

Docker from Dev and Ops perspective:

Ops perspective: The Ops perspective section will download an image, start a new container, run a command inside it, and destroy it.

Dev Perspective: The Dev Perspective will pull some app code from Github, inspect a Dockerfile, containerize the app, and run it using a container.

Note: This is part 1 which explains concepts, in the next part we'll be talking about the commands used in docker.

Thank you for reading the blog, Any feedback or questions in the comments below will be highly appreciated.