4 Linux technologies fundamental to containers (2024)

In previous articles, I have written about container images and runtimes. In this article, I look at how containers are made possible by a foundation of some special Linux technologies, including namespaces and control groups.

4 Linux technologies fundamental to containers (1)

Image by:

Figure 1: Linux technologies that contribute to containers

Linux technologies make up the foundations of building and running a container process on your system. Technologies include:

  1. Namespaces
  2. Control groups (cgroups)
  3. Seccomp
  4. SELinux

Namespaces

Namespaces provide a layer of isolation for the containers by giving the container a view of what appears to be its own Linux filesystem. This limits what a process can see and therefore restricts the resources available to it.

There are several namespaces in the Linux kernel that are used by Docker or Podman and others while creating a container:

$ docker container run alpine ping 8.8.8.8$ sudo lsns -p 29413 NS TYPE NPROCS PID USER COMMAND4026531835 cgroup 299 1 root /usr/lib/systemd/systemd --switched...4026533105 mnt 1 29413 root ping 8.8.8.84026533106 uts 1 29413 root ping 8.8.8.84026533105 ipc 1 29413 root ping 8.8.8.8[...]

User

The user namespace isolates users and groups within a container. This is done by allowing containers to have a different view of UID and GID ranges compared to the host system. The user namespace enables the software to run inside the container as the root user. If an intruder attacks the container and then escapes to the host machine, they're confined to only a non-root identity.

Mnt

The mnt namespace allows the containers to have their own view of the system's file system hierarchy. You can find the mount points for each container process in the /proc/<PID>/mounts location in your Linux system.

UTS

The Unix Timesharing System (UTS) namespace allows containers to have a unique hostname and domain name. When you run a container, a random ID is used as the hostname even when using the — name tag. You can use the unshare command to get an idea of how this works.

$ docker container run -it --name nived alpine sh/ # hostname9c9a5edabdd6/ #$ sudo unshare -u sh# hostname isolated.hostname# hostname# exit$ hostnamehomelab.redhat.com

IPC

The Inter-Process Communication (IPC) namespace allows different container processes to communicate by accessing a shared range of memory or using a shared message queue.

# ipcmk -M 10MShared memory id: 0# ipcmk -M 20MShared memory id: 1# ipcs---- Message Queues ----key msqid owner perms used-bytes messages---- Shared Memory Segmentskey shmid owner perms bytes nattch status0xd1df416a 0 root 644 10485760 00xbd487a9d 1 root 644 20971520 0[...]

PID

The Process ID (PID) namespace ensures that the processes running inside a container are isolated from the external world. When you run a ps command inside a container, you only see the processes running inside the container and not on the host machine because of this namespace.

Net

The network namespace allows the container to have its own view of network interface, IP addresses, routing tables, port numbers, and so on. How does a container able to communicate to the external world? All containers you create get attached to a special virtual network interface for communication.

Control groups (cgroups)

Cgroups are fundamental blocks of making a container. A cgroup allocates and limits resources such as CPU, memory, network I/O that are used by containers. The container engine automatically creates a cgroup filesystem of each type, and sets values for each container when the container is run.

SECCOMP

Seccomp basically stands for secure computing. It is a Linux feature used to restrict the set of system calls that an application is allowed to make. The default seccomp profile for Docker, for example, disables around 44 syscalls (over 300 are available).

The idea here is to provide containers access to only those resources which the container might need. For example, if you don't need the container to change the clock time on your host machine, you probably have no use for the clock_adjtime and clock_settime syscalls, and it makes sense to block them out. Similarly, you don't want the containers to change the kernel modules, so there is no need for them to make create_module, delete_module syscalls.

SELinux

SELinux stands for security-enhanced Linux. If you are running a Red Hat distribution on your hosts, then SELinux is enabled by default. SELinux lets you limit an application to have access only to its own files and prevent any other processes from accessing them. So, if an application is compromised, it would limit the number of files that it can affect or control. It does this by setting up contexts for files and processes and by defining policies that would enforce what a process can see and make changes to.

SELinux policies for containers are defined by the container-selinux package. By default, containers are run with the container_t label and are allowed to read (r) and execute (x) under the /usr directory and read most content from the /etc directory. The label container_var_lib_t is common for files relating to containers.

Wrap up

Containers are a critical part of today's IT infrastructure and a pretty interesting technology, too. Even if your role doesn't involve containerization directly, understanding a few fundamental container concepts and approaches gives you an appreciation for how they can help your organization. The fact that containers are built on open source Linux technologies makes them even better!

This article is based on atechbeatlyarticle and has been adapted with permission.

4 Linux technologies fundamental to containers (2)This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

4 Linux technologies fundamental to containers (2024)

FAQs

What is Linux container technology? ›

A Linux® container is a set of 1 or more processes that are isolated from the rest of the system. All the files necessary to run them are provided from a distinct image, meaning Linux containers are portable and consistent as they move from development, to testing, and finally to production.

Which of the following Linux technologies is responsible for isolated nature of containers? ›

Linux containers make use of kernel interfaces such as cnames and namespaces, which allow multiple containers to share the same kernel while running in complete isolation from one another.

What Linux feature is used to provide isolation for containers? ›

Linux namespaces allow the operating system to provide a process with an isolated view of one or more system resources.

What is an example of a Linux container? ›

LXD is a system container and a virtual machine manager that runs on top of LXC, enhancing the experience and enabling easier control and maintenance. LXD is image-based and provides images for a wide number of different Linux distributions.

What are container technologies? ›

Containers are packages of software that contain all of the necessary elements to run in any environment. In this way, containers virtualize the operating system and run anywhere, from a private data center to the public cloud or even on a developer's personal laptop.

What are the five important features of Linux? ›

The Kernel, Hardware layer, System library, Shell, and System utility are the main components of the Linux Operating System's architecture. The Kernel is the most crucial operating system component since it is responsible for all of LINUX's essential functions.

What are the essential features of container? ›

Inside a container are all the necessary executables, binary code, libraries, and configuration files. Compared to server or machine virtualization approaches, however, containers do not contain operating system images. This makes them more lightweight and portable, with significantly less overhead.

What are the three core technologies used to implement Red Hat Enterprise Linux containers? ›

Red Hat Enterprise Linux implements Linux Containers using core technologies such as Control Groups (Cgroups) for Resource Management, Namespaces for Process Isolation, SELinux for Security, enabling secure multi-tenancy and reducing the risk of security exploits.

What Linux technology does Docker containers use internally? ›

The underlying technology

Docker is written in the Go programming language and takes advantage of several features of the Linux kernel to deliver its functionality. Docker uses a technology called namespaces to provide the isolated workspace called the container.

How are containers implemented in Linux? ›

Containers in Linux are implemented using cgroups in order to manage resources and separate processes. Linux namespaces: Linux namespaces are a kernel feature designed to limit the visibility for a process or cgroup to the rest of the system.

How does container technology work? ›

A container image is a fixed, static file which contains executable code that allows it to run an isolated process in a computing environment. The image consists of system libraries and binaries (which are system tools, and other platforms settings) needed by a software program to run on the containerization platform.

Which command you may use to manage containers in a Linux system? ›

One of the most basic and essential Linux commands for managing Docker containers is docker ps. This command shows you all the containers that are currently running on your system, along with their names, IDs, statuses, ports, and images.

Where are containers stored in Linux? ›

On a linux system, docker stores data pertaining to images, containers, volumes, etc under /var/lib/docker.

How does a Linux Docker container work? ›

Docker uses resource isolation in the OS kernel to run multiple containers on the same OS. This is different than virtual machines (VMs), which encapsulate an entire OS with executable code on top of an abstracted layer of physical hardware resources.

What is the difference between Docker and Linux container? ›

Traditional Linux containers use an init system that can manage multiple processes. This means entire applications can run as one. The Docker technology encourages applications to be broken down into their separate processes and provides the tools to do that. This granular approach has its advantages.

What is the difference between Docker and Linux containers? ›

LXC provides a set of tools to manage your container as well as templates to create a virtual environment of the most common Linux OS. Docker is an open-source containerization technology that focuses on running a single application in an isolated environment.

What is the difference between Linux container and Linux VM? ›

A container is a software code package containing an application's code, its libraries, and other dependencies. Containerization makes your applications portable so that the same code can run on any device. A virtual machine is a digital copy of a physical machine.

Is Kubernetes a Linux container? ›

Kubernetes is an open source platform that automates Linux container operations. It eliminates many of the manual processes involved in deploying and scaling containerized applications. Kubernetes gives you the platform to schedule and run containers on clusters of physical or virtual machines.

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6200

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.