Containerization
Tags: containers, docker, lxc, cloud
Published: 2021-06-14 11:25:57

---
title: Containerization
published: true
description: what is containerization and how it evolved
tags: containers, docker, lxc, cloud
cover_image: https://bojana.dev/wp-content/uploads/2021/06/barrett-ward-5WQJ_ejZ7y8-unsplash-930x620.jpg
---

<!-- wp:paragraph -->
<p>In the last article, we talked about what <a href="https://bojana.dev/virtualization/">virtualization</a> is and how important the concept and technology is in the whole cloud computing paradigm.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now I want we talk about <em>containerization </em>- a different approach to isolation that does not use a hypervisor, but instead it relies on a specific kernel features that isolate processes from the rest of the system.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So in short <strong>containerization</strong> is a form of operating system virtualization, where we have applications running in isolated user spaces called <strong>containers.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Each process "container" or "jail" has a <strong>private root file system</strong> and <strong>process namespace</strong>.&nbsp;<br>While sharing the kernel and other services of the underlying OS, they cannot access files or resources outside of their container.<br>In essence, containers are fully packaged and portable computing environments.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":80,"width":339,"height":318,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://bojana.dev/wp-content/uploads/2021/06/image-1.png" alt="" class="wp-image-80" width="339" height="318"/><figcaption>Source: <a href="https://www.amazon.com/UNIX-Linux-System-Administration-Handbook/dp/0134277554">Unix And Linux System Administration Handbook</a></figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>We said that this type of virtualization does not require hypervisor, and because there is no need for the virtualization of the hardware, resource overhead for this type of virtualization is low.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This means container start up time is pretty quick, or if you will start time is pretty short. Creation of a container has the overhead of creating a Linux process, which can be of the order of the miliseconds, while creating a VM can take seconds.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The containerized application can be run on various types of infrastructure—on bare metal, within VMs, and in the cloud—without needing to refactor it for each environment</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How then containers relate to VMs?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Both are portable, isolated, execution environments, and both look and act as a full operating systems.<br>Unlike VM, which has an OS kernel, drivers to interact with hardware etc. a container is merely a mimic of an operating system. Container itself is abstracted away from the host OS, with only limited access to underlying resources - we can say it is a lightweight VM.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The containers-on-VMs architecture is standard for containerized applications that need to run on public cloud instances.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How containerization actually works?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We said that containerization relies on specific kernel features, but which features are those? <br>Containerization as we know it evolved from <strong>cgroups</strong>, a feature for isolating and controlling resource usage (e.g., how much CPU and RAM and how many threads a given process can access) within the Linux kernel.<br>cgroups were originally developed by Paul Menage and Rohit Seth of Google, and their first features were merged into Linux 2.6.24. Cgroups became Linux containers (<a href="https://linuxcontainers.org/lxc/introduction/" data-type="URL" data-id="https://linuxcontainers.org/lxc/introduction/">LXC</a>), with more advanced features for namespace isolation of components, such as routing tables and file systems.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Namespaces </strong>are a kernel mechanism for limiting the visibility that a group of processes has of the rest of a system. For example you can limit visibility to certain process trees, network interfaces, user IDs or filesystem mounts. namespaces were originally developed by Eric Biederman, and the final major namespace was merged into Linux 3.8.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Since kernel version 5.6, there are 8 kinds of namespaces. Namespace functionality is the same across all kinds: each process is associated with a namespace and can only see or use the resources associated with that namespace, and descendant namespaces where applicable. This way each process (or process group thereof) can have a unique view on the resources.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>bojana@linux:~$ sudo lsns -p 270
        NS TYPE   NPROCS PID USER COMMAND
4026531835 cgroup    130   1 root /sbin/init
4026531836 pid       126   1 root /sbin/init
4026531837 user      130   1 root /sbin/init
4026531838 uts       123   1 root /sbin/init
4026531839 ipc       126   1 root /sbin/init
4026531840 mnt       114   1 root /sbin/init
4026531992 net       126   1 root /sbin/init</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">In Linux, <code>lsns</code> lists information about all the currently accessible namespaces</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>cgroup</li><li>mnt (mount points, filesystems)</li><li>pid (processes)</li><li>net (network stack)</li><li>ipc (System V IPC)</li><li>uts (hostname)</li><li>user (UIDs)</li><li>time namespace</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Modern containers evolved from these 2 kernel features, and LXC served as a basis for <strong><a href="https://www.docker.com/">Docker</a></strong> launched in 2013. In it's early years it was based on using LXC, but later developed its own lib instead.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Docker</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":84,"width":261,"height":241,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://bojana.dev/wp-content/uploads/2021/06/PinClipart.com_shipping-container-clip-art_3317152.png" alt="" class="wp-image-84" width="261" height="241"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>For most people nowadays when you say "container" Docker is the first association, but we see that the containerization technology is not that new (cgroups dating back to 2008). However, Docker expansion can be contributed to the set of tools it introduced taking advantage of already existing containerization technology.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Because of the rapid evolvement of docker tools, and new versions being incompatible with existing deployments, to counter this Docker Inc. became one of the founder member of <a href="https://opencontainers.org/">Open Container Initiative</a>, <em> a consortium whose mission is to guide the growth of container technology in a healthily competitive direction that fosters standards and collaboration.</em></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We will be talking about docker architecture and docker as a container engine in one of the following articles.</p>
<!-- /wp:paragraph -->

Post originally published on : <a href="http://bojana.dev"><b>bojana.dev</b></a>