Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Linux Namespaces

Direct answer

Linux namespaces isolate what a process sees: pid, net, mnt, uts, ipc, user and cgroup namespaces. Containers combine them so each container has its own processes, network, filesystem and hostname.

When to use this

Use it to understand container isolation or to enter a container's view for troubleshooting.

First 30 seconds

1. Host PID of the container: docker inspect -f '{{.State.Pid}}' <c> / crictl inspect.

2. lsns -p <pid> — namespaces.

3. Enter: nsenter -t <pid> -n ip a.

4. Shared host namespaces? check spec (hostNetwork/hostPID).

5. Avoid unless required.

Operational verification

process → set of namespaces → isolated views

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to understand container isolation or to enter a container's view for troubleshooting.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Get the host PID with docker inspect -f {{.State.Pid}} <name> or crictl inspect. Run lsns -p <pid> to list its namespaces. Use nsenter -t <pid> -n -m to run host tools inside the container namespaces without installing them in the image.

Step 2 Common failures Narrow the fault

Running with --network host, --pid host or --privileged removes isolation that users often assume is there. Debug tools may show host data if they run outside the container namespaces. User namespace remapping changes file ownership on bind mounts, which shows up as permission denied.

Key points

nsenter -t <pid> -n runs host tools inside a container's network namespace. User namespaces map container root to an unprivileged host user (rootless). Sharing host namespaces (--network host, hostPID) removes isolation.

Key checks
  • lsns -p <pid> — namespaces of a process
  • nsenter -t <pid> -n <cmd> — run a command in its network namespace
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state
ReferenceWhat it is1 section · depth on demand

How it works

The kernel creates namespaces when the runtime calls clone() or unshare() with namespace flags. A process in a new PID namespace sees itself as PID 1, a new network namespace starts with only a loopback interface, and a mount namespace has its own mount table. The user namespace maps container UIDs to unprivileged host UIDs, which is what rootless containers rely on. Because every container still uses the host kernel, a kernel vulnerability or a privileged container can break out of this isolation.

ReferenceImportant terms & boundaries2 sections · depth on demand

Common mistakes

  • Assuming namespaces alone give strong isolation.

In depth

A container is an ordinary process placed in its own set of namespaces. Each namespace type isolates one kind of resource:

NamespaceIsolatesSeen inside the container
pidProcess IDsOwn PID 1; cannot see host processes
netInterfaces, routes, iptables, socketsOwn eth0, own loopback
mntMount tableImage root filesystem and volumes only
utsHostname, domain nameContainer hostname
ipcSystem V IPC, POSIX queuesOwn shared memory
userUID/GID mappingRoot in the container can map to an unprivileged host UID
cgroupView of the cgroup treeOwn cgroup as root

Worked check — prove which namespaces a container shares with the host

PID=$(docker inspect -f '{{.State.Pid}}' web)
ls -l /proc/$PID/ns/net /proc/1/ns/net
# net:[4026532281]  vs  net:[4026531840]  → different inode = own network namespace
nsenter -t $PID -n ip -br addr       # host's ip binary, container's network view

If both links show the same inode number, the container shares that namespace with the host (for example --network host).

Limits of the model

  • All containers share one kernel. A kernel vulnerability or an exposed host device crosses every namespace boundary.
  • Without a user namespace, UID 0 in the container is UID 0 on the host; capabilities and seccomp are then the main protection.
  • Some kernel interfaces are not namespaced at all (for example most of /sys, the kernel keyring and the system clock); runtimes mask or mount them read-only.
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
linux namespaceslinux namespaces containersnsenter
Confirmation

Confirm action

Continue?