Thread

Article header

Introduction to containers

What is a container, what is a virtual machine, and what are the differences between these two concepts?

Container

In IT, a container is a lightweight and portable unit of software that packages an application and all its dependencies, allowing it to run consistently in any environment.

Why use containers?

Primarily, to port our application and run it consistently, whether on our PC or in any development environment. They also allow for fast and secure deployments.

A bit of history

In the 1960s and 1970s, IBM introduced virtualization to mainframes, which allowed multiple operating systems to run on a single physical machine.

In 1992, Finnish programmer Linus Torvalds released version 0.12 of the Linux kernel under the GNU GPL license. Since then, Linux has been considered free software.

In 2008, Linux Containers, also known by their acronym LXC, emerged. Leveraging features such as cgroups and namespaces available starting from Linux kernel version 2.6.29, LXC enables the development of operating-system-level virtualization technology. LXC allows a machine running Linux to execute multiple instances of isolated user-space environments, giving rise to the term container.

In 2013, Docker was released as open-source software, initially based on LXC. However, the following year, with the release of Docker version 0.9, it stopped using LXC and switched to its own engine called libcontainer, written in Go.

Since then, Docker has grown in popularity, becoming one of the most starred projects on GitHub, with numerous forks and thousands of contributors.

Virtual Machines

Often, when introducing the concept of a container, there is confusion about whether it is a type of virtual machine.

Virtual Machine Concepts

A virtual machine (VM) is an isolated environment that emulates a complete computer system (at the hardware level), allowing an operating system and applications to run as if they were on a physical computer, while using shared hardware resources from the host.

Each virtual machine requires the allocation of resources such as CPU, disk, memory, network, etc., as well as its own operating system. A hypervisor is needed to manage these tasks.

Some of the most well-known hypervisors are:

Virtual Machine Architecture

Each virtual machine requires a full operating system (kernel, system utilities, user interface, etc.) in order to function.

image

This means that, in order to run just one application or a component of a larger application, a full OS must be installed and maintained for each VM. Often, the operating system consumes more resources than the application itself.

Container Architecture

Each container uses the host operating system's kernel. It only includes the applications and the dependencies required for it to function.

image

Containers are isolated at the process level, using features of the host kernel for their operation. It is also possible for containers to share dependencies and file systems when necessary. In addition, we can limit CPU and memory usage for each container in a way similar to a virtual machine.

Due to their efficiency, container architecture is considered a form of lightweight virtualization.

Containers vs. VM

| Characteristic | VM | Container | |----------------|----|-----------| | Isolation | Full (hardware-level) | Lightweight (process-level) | | Resource Usage | Higher resource consumption | Lower resource consumption | | Startup | Slow | Fast | | Operating System | Multiple OS per VM | Shares the host kernel | | Portability | Limited, depends on the hypervisor | High, runnable in any environment | | Security | Strong hardware-level isolation | Process-level isolation |

This does not mean that virtual machines are obsolete compared to containers. In some situations, using containers will not be possible. For example, when different operating systems are required for each application.

Use cases for containers

  • Microservices Development: Suitable for microservices architectures where each application component is deployed independently.
  • Continuous Integration and Continuous Deployment: They simplify the creation of CI/CD pipelines, enabling fast and frequent deployments.
  • Application Containerization: Infrastructure for applications not originally designed for containers can be modernized. Containerization improves portability and deployment automation.
  • Simple Application Deployment: With just a copy-and-paste command or a small text file, complex applications can be deployed quickly in testing environments.

There are several technologies that use containers, including LXC, LXD, Docker, and Podman. In addition, there are container orchestration and management tools such as Docker Swarm, Kubernetes, and OKD.

Replies (1)