What are Containers?
Tags: containers, devops, beginners, cloud
Published: 2022-02-04 09:18:02

Words like **"containers"** and **"containerization"** are being bandied about in the tech world. This technology has grown tremendously in recent years, and it is expected to grow even more in the coming years. Today I wanted to provide a brief introduction to some key container concepts, get beginners acquainted with what actually is containers and containerization. 

In this post, we will go over key concepts related to how applications consume computational resources, as well as key Linux tools and why these concepts are important for understanding how containers work.

First, let's start with the seminal question, 

## What are containers?

One way to think about them is that they're **lightweight virtual machines**. With a virtual machine, you have to virtualize an entire operating system as well as the software you want to run. This makes VMs really resource heavy.

Containers get their names from their physical counterparts: shipping containers. Containers make it simple to package goods together into a single shipment when shipping items to the other side of the world. The standard shape and size allows for efficient packing of many containers onto a ship, the walls provide isolation, preventing items from being mixed together, they are portable, designed to be easily moved and shipped, and there is a clear separation of concerns. One party is in charge of packing the container with the appropriate items, while another is in charge of ensuring that the container arrives at its destination.

![Shipping Containers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yd8somazc2a44r5y3xa4.jpeg)

A container is an executable software unit in which application code, along with its libraries and dependencies, is packaged in common ways so that it can be run anywhere, whether on a desktop, on-premises, or in the cloud. Containers accomplish this by utilizing a type of operating system virtualization in which operating system features are used to both isolate processes and control the amount of CPU, memory, and disc storage that those processes have access to.

Because the operating system is often the single most resource-intensive piece of hardware on your computer, running multiple OSs on the same computer just to have separate environments consumes a significant amount of your resources. To address this issue, the Linux operating system began to use containers. The idea is simple: why run a new OS for each VM if you already have a Linux OS running on your computer? Instead, for each VM, you can use the OS's core, known as the kernel. As a result, the VMs only run the software that is required.

## Benefits of containers

* **Containers are lightweight:** 
The primary benefit of containers, particularly when compared to virtual machines, is the level of abstraction they provide, which allows them to be lightweight and portable. They share the machine's OS kernel, removing the need for a separate operating system instance for each application. As a result, container files are smaller and less resource-intensive. Because they are smaller in size, especially when compared to virtual machines, they can be spun up quickly and are better suited to cloud-native applications that scale horizontally.

![lightweight](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7r1o5gkrr21cf53258uc.png) 

* **Portable and platform independent:**
Containers carry all of their dependencies with them, which means that software can be written once and then run across laptops, the cloud, and on-premises computing environments without needing to be reconfigured. This portability also ensures consistency in your environment, so you don't have to worry about installing different dependencies in different environments.

![Containerization](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aetrv45adky5bh4liyt5.png) 

* **Benefits in modern development and architecture:** 
Containers are an ideal fit for modern development and application patterns that require regular deployments of incremental changes due to their portability and consistency across platforms, as well as their small size.

![Modern development and architeture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78xqpjz74p9m7yoqaq90.png) 

* **Improve Utilization:**
Containers, like virtual machines before them, allow developers and operators to improve physical machine CPU and memory utilization. Containers go even further by enabling a microservice architecture, which allows application components to be deployed and scaled more precisely.

Virtual machines (VMs) are frequently mentioned when people discuss virtualization. Virtualization can, in fact, take many forms, and containers are one of them. So, what is the distinction between VMs and containers?

## Containers vs VMs

Virtual machines (VMs) virtualize the underlying hardware, allowing multiple operating system (OS) instances to run on the hardware. Each virtual machine (VM) runs an operating system and has access to virtualized resources that represent the underlying hardware.

Virtual machines have numerous advantages. These benefits include the ability to run multiple operating systems on the same server, more efficient and cost-effective physical resource utilization, and faster server provisioning. Furthermore, binaries, libraries and other applications are present in the virtual machine, allowing applications to run.

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7htxc33lr7c0kemp02oj.png">
  <figcaption>Image source: Docker</figcaption>
</figure>
 

A container virtualizes the underlying OS, giving the containerized app the illusion that it has complete control over the OS (including CPU, memory, file storage, and network connections). Because the differences in the underlying OS and infrastructure are abstracted, the container can be deployed and run anywhere as long as the base image is consistent. This is extremely appealing to developers.

Containers virtualize the operating system rather than the infrastructure in this way. This allows the infrastructure to have a single copy of the operating system, saving a significant amount of space. The container engine is responsible for the execution of binaries, libraries, and applications. The obvious advantage of containers is that they eliminate the need to run a separate operating system instance for each virtual environment. Instead, one operating system is shared by all containers. 

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61jns1fjtsx52kiovtlc.png">
  <figcaption>Image source: Docker</figcaption>
</figure>
 
**Point to be noted:** Although containers are portable, they are limited to the operating system for which they are designed. A container for Linux, for example, cannot run on Windows, and vice versa.

## Use Cases of containers

* **Microservices:** Containers enable microservices and distributed systems. Complex applications can be easily isolated, deployed, and scaled with them by utilizing individual container building blocks.

![Microservices](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6a8x9k18pcl51x33fje.png) 

* **Continuous integration and deployment (CI/CD) assistance:** Container images make it easier for DevOps teams to implement and automate CI/CD pipelines by simplifying building, testing, and deployments. Repetitive jobs and tasks are deployed. Containers allow you to easily deploy, scale, and manage background processes such as ETL functions or batch jobs, allowing them to run much more efficiently.

![CI/CD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7x5dyvggzebkzfxi5c0.png) 

* **Migrations involving "Lift and Shift":** This method is similar to a cloud migration strategy in that it allows you to quickly modernize your applications without investing in refactoring or rewriting existing code. Containers make deployment easier even if you can't take advantage of all the benefits of a fully modular, container-based architecture.

![Lift and Shift Migration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ugwiswoo6agqzocm3krg.jpg) 

* **Existing applications are being refactored:** It requires significantly more resources than the "lift and shift" approach, which necessitates refactoring existing code to fully benefit from container-based architecture. Depending on your app, this could be a required step or simply the next improvement. 
<br>

* **Hybrid and multi-cloud computing:** It doesn't matter where you deploy your apps in containers. As a result, you may benefit from combining existing on-premise infrastructure with multiple cloud platforms to improve cost optimization and operational efficiency.  

![Multi-cloud](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vganiq8z3cng0twbemzw.png) 

* **Containers as a service:** Containers as a service (CaaS) enables container-based virtualization by distributing container engines, orchestration, and underlying compute resources as cloud services. With CI/CD pipeline automation, this simplifies development and allows DevOps teams to deploy applications more quickly.    

![CaaS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cetaekqubt8av0sznxtc.png)  

So by reading this blog post, you should understand what a container is and how it differs from a virtual machine, as well as the benefits that containers provide in software development.

I will be listing down some free useful resources from which you can learn more about containers and containerization
* [**Docker**](https://www.docker.com/resources/what-container)
* [**KubeAcademy**](https://kube.academy/courses/containers-101)
* [**cloud academy**](https://cloudacademy.com/library/containers/)

So, in conclusion, containers don't really exist, but they are abstractions, and like most abstractions, they can be very good or very bad, and in this case, container abstractions provide a lot of value, are, and are really a pretty amazing technology. So, even if containers don't exist, long live the containers!!🙌

## Happy Containerizing!!🚢🏗️