Linux Curriculum
On this page
What Are Namespaces
1. The Core Secret of Containers: "Containers Do Not Exist"
One of the most foundational realizations in modern cloud and DevOps engineering is that there is no such thing as a "container" inside the Linux kernel.
Unlike a Virtual Machine (which virtualizes physical CPU, RAM, and BIOS via a hypervisor like KVM or VMware), a container is simply a standard Linux process running directly on the host kernel, but constrained and isolated by two foundational kernel primitives:
- Linux Namespaces: Control WHAT a process can SEE (Isolation / Virtual Views).
- Control Groups (cgroups): Control HOW MUCH a process can USE (Resource Limiting).
2. The 8 Linux Kernel Namespaces
A Namespace wraps a global system resource in an abstraction that makes it appear to the processes within the namespace that they possess their own isolated instance of that resource.
3. How the Kernel Represents Namespaces: /proc/<PID>/ns/
Every process running on a Linux machine has a dedicated subdirectory at /proc/<PID>/ns/ containing symbolic links representing its membership in each namespace:
The numbers inside the brackets (e.g., net:[4026531992]) are inode identifiers.
- If Process A and Process B share the same inode number for
net, they share the same network namespace (can communicate overlocalhost:8080). - If their inode numbers differ, they are in completely separate, isolated network namespaces!
4. The Two Fundamental Commands: unshare and nsenter
The Linux util-linux package provides two CLI tools to manipulate namespaces directly without Docker:
1. unshare: Create a New Namespace
Spawns a new program running inside a brand-new, isolated namespace:
2. nsenter: Enter an Existing Container's Namespace
Allows an engineer or debugger to inject a terminal shell directly into the namespace of a running Docker container or Kubernetes pod:
Now, running ip a or tcpdump reveals the container's virtual network interface directly from the host!
5. Summary Takeaways
- Containers are standard Linux processes isolated by Namespaces and constrained by Cgroups.
- Namespaces determine what a process can see (PIDs, mounts, networks, users).
- Every process's namespace memberships are visible as inode links in
/proc/<PID>/ns/. - Use
unshareto create new isolated namespaces manually. - Use
nsenterto inject debugging tools directly into active container namespaces.