Cloud Native 5 min read

Master Docker’s Core: Namespaces and Cgroups Explained

This article explains Docker’s fundamental technologies—how Linux namespaces provide process, network, and filesystem isolation while cgroups enforce resource limits such as CPU, memory, I/O, and process counts—offering a concise guide for building secure, efficient containerized applications.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Master Docker’s Core: Namespaces and Cgroups Explained

Docker Core Technologies

Docker is essential for large‑scale architectures and a cornerstone of cloud‑native computing. Its core lies in isolating and managing processes and resources.

Diagram
Diagram

Namespaces – Isolation

Namespaces provide isolated views of system resources such as processes, network, file‑system mounts, hostnames, and user IDs, making each container appear as an independent OS.

pid : isolates process IDs; each container has its own PID 1.

net : isolates network devices, ports, routing; containers get independent network interfaces.

ipc : isolates inter‑process communication like semaphores and shared memory.

mnt : isolates mount points and filesystem view; containers have separate root filesystems.

uts : isolates hostname and domain name; each container can set its own hostname.

user : isolates user and UID mappings; enables rootless containers.

Example:

<code>docker run -it --pid=host ubuntu</code>

Cgroups – Resource Management

Cgroups limit and monitor the resources a container can use, preventing contention and ensuring system stability.

cpu : control CPU usage (e.g., --cpus="1.0" limits to one CPU core).

cpuacct : account for CPU usage.

memory : control memory usage.

blkio : control block device I/O.

net_cls : tag network packets for traffic control.

pids : limit the number of processes.

Examples:

<code>docker run -it --cpus="1.0" ubuntu</code>
<code>docker run -it --cpu-shares=512 ubuntu</code>
<code>docker run -it --device-write-bps /dev/sda:5mb ubuntu</code>
<code>sudo tc qdisc add dev vethXXXX root tbf rate 1mbit burst 32kbit latency 400ms</code>
<code>docker run -it --pids-limit=100 ubuntu</code>

These mechanisms together give Docker containers isolation and resource control, forming the foundation of containerization.

Dockerresource managementContainerizationLinuxcgroupsNamespaces
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.