Skip to content
BENIBIX Learn

Linux Namespace

Infrastructure📦 ContainersContainer Basics

Also known as Namespaces (Linux), Kernel Namespace, PID Namespace, Network Namespace

A Linux trick that gives programs a private view of the system. Each box is built on it.

Think of it like

Think of it like a room with the blinds down. You only see what is in your own room.

Example

Lucy runs ps inside a container and sees one process. On the host, the same command lists hundreds.

Why it matters

Namespaces are why a container cannot see the programs around it. They are the walls of the box.

Definition

A Linux namespace gives a group of programs their own private view of one part of the system. In a process namespace, the programs see only each other. In a network namespace, they get their own network cards and ports. Linux has eight kinds. They also cover files, users and the computer's name. A container is mostly a program started inside a set of these.

Example code

console
$ docker run --rm alpine ps
PID   USER     TIME  COMMAND
    1 root      0:00 ps
In its own process namespace, the box sees one program. That program is number 1.
Each container gets its own view of processes, network and files. Those private views are namespaces.

Common mistake

Thinking namespaces make a container as safe as a virtual machine. All of them still share one kernel. A flaw in it can reach them all.

Key takeaways

  1. 1
    A private view. Programs see only their own part.
  2. 2
    Eight kinds. Processes, network, files, users and more.
  3. 3
    One shared kernel. Walls, not a separate machine.

Compare