DEV Community

Cover image for Demystifying how containers work
Bruno Ciccarino λ
Bruno Ciccarino λ

Posted on

2 1 1 1

Demystifying how containers work

When we talk about containers, people often confuse them with virtualization. It seems like running a program inside a virtual machine. But containers are completely different from virtual machines!

Image description

If I were to summarize the difference in a single sentence, the virtual machine runs a new kernel, possibly on another architecture, such as x86 on top of ARM. However, the container reuses the same kernel, necessarily on the same hardware architecture. That's the big difference.

Linux containers are completely different from BSD containers. Windows and Mac have different structures for containers. Windows can run containers to run Windows apps. This is lightweight, but when Windows or MacOS need to run Linux apps, they actually start a Linux virtual machine first, such as WSL. Therefore, it does involve virtualization, and it is inside this machine that a Docker desktop creates Linux containers.

But how do containers work in practice? The magic happens thanks to a Linux kernel feature called cgroups (control groups), which allows you to limit and isolate the use of resources (CPU, memory, disk) by a set of processes. In addition, namespaces isolate the file system, network, PID and other operating system resources.

Image description

Docker, the most popular tool for creating and managing containers, uses these Linux kernel features to create an isolated environment for each container. A file called Dockerfile defines the instructions for building a container, including the base image, dependencies and commands to run the application.

In short, containers are an abstraction over the operating system resources, providing a lightweight and isolated environment for running applications. The combination of cgroups and namespaces allows multiple containers to be run on the same physical machine efficiently and securely.

Please leave your appreciation by commenting on this post!

It takes just one minute and is worth it for your career.

Get started

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay