Skip to content
Blog

PID, IPC, and UTS Namespaces in Docker: Deep Dive into Kernel Isolation

Understand how Linux PID, IPC, and UTS namespaces isolate processes, shared memory, and hostnames in Docker, and how flags like --pid=host and --ipc operate.

Published on • November 17, 2026

AI Assistant

Linux namespaces form the foundation of containerization. While Network (net) and Mount (mnt) namespaces frequently receive the spotlight, PID, IPC, and UTS namespaces are equally vital for process isolation, inter-process communication, and system identity.

In Docker, every container gets its own set of kernel namespaces by default. However, advanced workloads — such as system monitoring, high-performance shared memory processing (e.g., PostgreSQL, PyTorch, or ROS), and custom network tooling — require a deeper understanding of how these three namespaces work and when to break isolation boundaries safely.


1. PID Namespaces: Process Tree Isolation

The PID (Process ID) namespace provides processes with an isolated view of the system process tree.

How PID Namespaces Work

When Linux boots, PID 1 is assigned to the init system (such as systemd). When Docker creates a container with a new PID namespace:

  1. The primary entrypoint process inside the container becomes PID 1 within that container’s PID namespace.
  2. On the host kernel, however, that same process is assigned a standard PID (e.g., PID 14829) in the host’s root PID namespace.
  3. Processes inside the container cannot see or send signals to processes in parent or sibling PID namespaces.
Host Root PID Namespace
├── PID 1 (systemd)
├── PID 940 (dockerd)
└── PID 14829 (container process) <--- [Mapped to PID 1 in Container Namespace]
                                       ├── PID 1 (nginx main process)
                                       └── PID 7 (nginx worker process)

Inspecting Process Mappings

You can observe process ID mapping using standard CLI tools. Run a detached background container:

docker run -d --name pid-demo nginx:alpine

Get the container’s main PID on the host system:

HOST_PID=$(docker inspect --format '{{ .State.Pid }}' pid-demo)
echo "Host PID: $HOST_PID"

If you execute ps aux inside the container, you will see nginx running as PID 1:

docker exec pid-demo ps aux

Output:

PID   USER     TIME  COMMAND
    1 root      0:00 nginx: master process nginx -g daemon off;
    7 nginx     0:00 nginx: worker process

Joining Namespaces: --pid=host and --pid=container:NAME

Docker allows containers to share PID namespaces in two key scenarios:

A. Host Process Visibility (--pid=host)

Debugging tools, APM agents, and eBPF profilers often need access to the entire host process tree:

docker run --rm -it --pid=host htop

With --pid=host, the container shares the host’s root PID namespace. The container process can see every process running on the host system and send signals to them (subject to Linux capabilities and MAC enforcement like AppArmor/SELinux).

B. Container-to-Container PID Sharing (--pid=container:<NAME_OR_ID>)

When debugging a minimal container (like a distroless or scratch binary without a shell), you can attach a debug container directly to its PID namespace:

# Target production container with no debugging tools
docker run -d --name prod-app my-distroless-app:latest

# Attach a troubleshooting container sharing the target's PID namespace
docker run --rm -it --pid=container:prod-app nicolaka/netshoot gdb

2. IPC Namespaces: Inter-Process Communication Isolation

The IPC namespace isolates System V IPC objects and POSIX message queues. Specifically, it provides isolation for:

  • POSIX Shared Memory (/dev/shm)
  • System V Shared Memory (shmget, shmat)
  • System V Semaphore Arrays (semget, semop)
  • System V Message Queues (msgget, msgsnd)

Shared Memory Default Allocation

By default, Docker allocates a dedicated IPC namespace per container with a default /dev/shm size of 64MB:

docker run --rm alpine df -h /dev/shm

Output:

Filesystem                Size      Used Available Use% Mounted on
shm                      64.0M         0     64.0M   0% /dev/shm

For workloads relying on large shared memory segments (such as PyTorch multi-GPU training or PostgreSQL parallel query execution), 64MB can lead to bus errors (SIGBUS). You can expand the shared memory size using --shm-size:

docker run --rm --shm-size=2g postgres:16

Sharing IPC Between Containers (--ipc=host / --ipc=container:NAME)

To allow two high-performance microservices to exchange megabytes of data per millisecond via zero-copy shared memory, share their IPC namespace:

# Container A creates the shared memory segment
docker run -d --name producer-app --ipc=shareable my-producer:latest

# Container B attaches to Container A's IPC namespace
docker run -d --name consumer-app --ipc=container:producer-app my-consumer:latest

Alternatively, to share IPC memory segments directly with host processes:

docker run -d --ipc=host high-throughput-sensor-reader:latest

3. UTS Namespaces: System Identity and Hostname Isolation

The UTS (UNIX Timesharing System) namespace isolates two specific system identifiers returned by uname():

  1. Hostname (nodename)
  2. NIS Domain Name (domainname)

Hostname Isolation in Action

By default, Docker creates a UTS namespace for every container and sets the hostname to the container’s short 12-character ID:

docker run --rm alpine hostname

Output:

a1b2c3d4e5f6

You can explicitly override the UTS hostname using --hostname and --domainname:

docker run --rm --hostname api-node-01 --domainname internal.example.com alpine uname -n

Output:

api-node-01

Sharing Host UTS Namespace (--uts=host)

If a monitoring agent needs to inspect or set the host’s actual hostname, it can join the host’s UTS namespace:

docker run --rm -it --uts=host alpine hostname

Output:

production-worker-node-04.datacenter.internal

Namespace Flag Summary

NamespaceDocker FlagCommon Use Case
PID--pid=hostMonitoring agents (Datadog, eBPF, htop), host process diagnostics.
PID--pid=container:<id>Debugging sidecar containers attached to distroless app containers.
IPC--shm-size=2gML training (PyTorch, TensorFlow), relational databases (PostgreSQL).
IPC--ipc=host / --ipc=container:<id>Zero-copy high-frequency trading apps, IPC messaging daemons.
UTS--hostname=<name>Setting consistent service identifiers in cluster environments.
UTS--uts=hostSystem telemetry agents reading host nodename.

Key Takeaway

Takeaway: Linux PID, IPC, and UTS namespaces allow Docker to enforce strict isolation boundaries around processes, shared memory segments, and host identity. While container defaults provide robust isolation out of the box, understanding flags like --pid=host, --ipc=container:<name>, and --shm-size is critical when architecting high-performance shared memory applications, distroless debugging workflows, and host monitoring sidecars.


Sources