Container Isolation and Linux Namespaces
Containers are isolated process environments built on top of the host Linux kernel.
Overview
Containers are isolated process environments built on top of the host Linux kernel. Docker uses Linux namespaces as a primary isolation mechanism and combines them with control groups, capabilities, seccomp, security profiles, filesystem controls, and other mechanisms. Docker documents namespaces as the first and most straightforward form of container isolation.
1. What Is Container Isolation?
Container isolation means that processes running in a container normally have a restricted view of
the host's processes, network interfaces, mounts, IPC objects, hostnames, and user identities.
The important point is that containers are not separate physical machines. They share the host kernel.
Conceptually:
Host Linux Kernel
│
├── Container A
│ ├── Processes
│ ├── Network namespace
│ ├── Mount namespace
│ └── User namespace
│
├── Container B
│ ├── Processes
│ ├── Network namespace
│ ├── Mount namespace
│ └── User namespace
│
└── Host processes
Docker creates a set of namespaces and control groups when a container is started. Namespaces provide
isolation; cgroups provide resource accounting and limiting.
2. Why Linux Namespaces Matter
Linux namespaces allow processes to see a particular scoped view of system resources.
Without namespaces, a process inside a container could potentially see host processes, host network
interfaces, or other global resources directly.
With namespaces, the same Linux kernel can provide different views to different groups of processes.
This is one of the foundations of containerization.
3. Linux Namespace Types Used for Container Isolation
4. PID Namespace
The PID namespace isolates process ID numbering and process visibility.
A process can have a different PID inside a PID namespace than it has on the host. A container can
therefore have its own process tree.
Conceptually:
Host:
PID 1 system service
PID 200 dockerd
PID 500 container process
Container PID namespace:
PID 1 application
PID 2 child process
The container's process view is not equivalent to the host's complete process view.
Practical commands:
docker run --name pid-demo -d nginx
docker exec pid-demo ps aux
You can compare the container process view with host processes using standard Linux process tools.
5. Network Namespace
A network namespace provides a separate view of network resources such as network interfaces,
routing tables, and network sockets.
Docker containers normally receive their own network stack. Docker's security documentation explains
that a container does not automatically receive privileged access to another container's sockets or
interfaces.
Conceptually:
Container A
eth0 ──┐
│
Docker network
│
eth0 ──┘
Container B
Containers can communicate when the Docker network configuration permits it. Public port publishing
and network configuration determine how traffic can reach a container.
6. Mount Namespace
The mount namespace isolates the set of filesystem mount points visible to a process.
This is an important part of how a container receives its own filesystem view.
Conceptually:
Host filesystem
├── /etc
├── /var
├── /home
└── /var/lib/docker
Container mount view
├── /etc
├── /app
├── /tmp
└── container-specific mounts
The container does not simply receive unrestricted visibility of every host mount. Host paths can,
however, be deliberately shared through mechanisms such as bind mounts. Such sharing changes the
security boundary and should be configured carefully.
7. UTS Namespace
The UTS namespace isolates hostname and domain-name information.
This allows a container to have its own hostname without changing the host's hostname.
For example:
docker run --rm ubuntu hostname
The result is associated with the container's UTS namespace rather than changing the host's global
hostname.
8. IPC Namespace
The IPC namespace isolates System V IPC objects and POSIX message queues.
This helps prevent processes in separate IPC namespaces from automatically sharing the same IPC
resources.
IPC isolation matters for applications that use shared-memory segments, semaphores, message queues,
or related kernel IPC mechanisms.
9. User Namespace
The user namespace is especially important for security because it can map user and group IDs
inside a namespace to different IDs on the host.
For example, a process can appear as UID 0 (root) inside a user namespace while being mapped to an
unprivileged high-number UID on the host.
Docker's user namespace remapping feature can use this model to reduce the impact of a process that
has root privileges inside a container.
Example configuration:
{
"userns-remap": "testuser"
}
Docker documents that subordinate UID and GID ranges are managed through /etc/subuid and /etc/subgid.
The ranges must not overlap.
10. User Namespace Remapping vs Rootless Mode
These concepts are related but not identical.
userns-remap:
• Container users are remapped to less-privileged host IDs.
• The Docker daemon itself still runs with root privileges.
Rootless mode:
• The Docker daemon and containers run as a non-root user.
• Docker runs the daemon and containers inside a user namespace.
Therefore:
userns-remap → daemon root, containers mapped
Rootless → daemon non-root, containers non-root
Docker documents Rootless mode as a way to mitigate potential vulnerabilities in the daemon and
container runtime.
11. Namespaces and cgroups Are Different
A common interview mistake is to treat namespaces and cgroups as the same feature.
Namespaces answer questions such as:
• Which processes can I see?
• Which network interfaces can I see?
• Which mounts can I see?
• Which hostname do I see?
• Which user IDs do I see?
Cgroups answer questions such as:
• How much memory can this workload use?
• How much CPU can it consume?
• How can resource usage be accounted for?
• How can one workload be prevented from exhausting shared resources?
A simplified model is:
Namespaces → isolation and visibility
cgroups → resource accounting and limiting
12. Container Isolation Is Layered
Namespaces are not the entire Docker security model.
A container's security boundary is better understood as multiple layers:
Application
↓
Container configuration
↓
Namespaces
↓
Capabilities
↓
Seccomp
↓
AppArmor / SELinux where configured
↓
Linux kernel
↓
Host security
Docker's security documentation explicitly discusses namespaces, cgroups, daemon security, container
configuration, and kernel hardening as separate security considerations.
13. What Namespaces Do Not Protect Against
Namespaces provide isolation, but they do not make every container automatically secure.
Important examples include:
• A container can deliberately receive host resources through configuration.
• A container can receive additional privileges.
• Host paths can be shared through bind mounts.
• Host networking can be requested.
• Host PID namespace sharing can be requested.
• Kernel vulnerabilities can affect isolation.
• Docker daemon access is highly privileged.
• Other security controls such as capabilities, seccomp, and security profiles matter.
Therefore, container security must be evaluated from the complete configuration rather than from the
presence of namespaces alone.
14. Practical Demonstration: Inspect a Container
- Start a container:
docker run -d --name isolation-demo nginx
- Inspect it:
docker inspect isolation-demo
- Enter the container:
docker exec -it isolation-demo sh
- Inspect processes:
ps aux
- Inspect the hostname:
hostname
- Inspect network information:
cat /proc/net/dev
The exact output depends on the image and runtime environment, but these commands help demonstrate
that a container has its own process, hostname, filesystem, and network context.
15. Inspect Linux Namespace Information
Linux exposes namespace information through /proc.
On a Linux host, a process can be associated with namespace handles under:
/proc/<pid>/ns/
For example:
ls -l /proc/1/ns/
Typical entries include:
ipc
mnt
net
pid
user
uts
These entries point to namespace identifiers and are useful when studying Linux process isolation.
The exact namespace set depends on the kernel and configuration.
16. Sharing a Host Namespace
Docker allows specific namespaces to be shared with the host in some configurations.
For example:
--network=host
uses the host network namespace instead of a separate container network namespace.
Similarly, options such as:
--pid=host
share the host PID namespace.
These options can be useful for specialized workloads, but they reduce isolation and should be used
only when the workload actually requires them.
A useful rule is:
Separate namespace by default → share only when required.
17. Security Example: Why Host Namespace Sharing Matters
Suppose an application normally runs in its own PID namespace:
Host processes
│
└── Container PID namespace
│
└── Application
The application has a limited process view.
If host PID namespace sharing is enabled, the container's processes can have visibility into the
host PID namespace. This changes the isolation boundary.
The security impact therefore comes not just from the application image but from the runtime options.
18. Docker Security Configuration and Namespaces
A hardened container commonly combines namespace isolation with additional restrictions:
docker run -d --name secure-app --cap-drop=ALL --read-only --memory=512m --cpus=1 myapp:1.0
This example does not configure every possible security control. It demonstrates the principle of
layering isolation, reduced privileges, filesystem restrictions, and resource controls.
19. Common Misconceptions
Misconception 1: A container is a lightweight VM.
Reality: A container shares the host kernel.
Misconception 2: Namespaces provide complete security.
Reality: Namespaces are one layer of isolation.
Misconception 3: Root inside a container is always root on the host.
Reality: User namespaces can remap container IDs; however, configurations differ and other privileges
can affect the security boundary.
Misconception 4: cgroups isolate processes.
Reality: cgroups primarily provide resource accounting and limiting; namespaces provide the main
visibility/isolation mechanism.
Misconception 5: Containers cannot access each other.
Reality: Network and other sharing mechanisms can allow controlled communication between containers.
20. Interview Questions
1. What are Linux namespaces?
2. Why are namespaces important for containers?
3. What is a PID namespace?
4. What is a network namespace?
5. What does a mount namespace isolate?
6. What is a UTS namespace?
7. What does an IPC namespace isolate?
8. What is a user namespace?
9. How is userns-remap different from Rootless mode?
10. What is the difference between namespaces and cgroups?
11. Can containers share a host namespace?
12. What happens when --network=host is used?
13. What happens when --pid=host is used?
14. Why are namespaces not sufficient by themselves for container security?
15. How would you investigate namespace isolation on a Linux host?
21. Production Checklist
Before deploying a containerized workload:
- Keep required namespaces isolated.
- Avoid host namespace sharing unless required.
- Run application processes as non-root where practical.
- Drop unnecessary Linux capabilities.
- Keep Docker's default seccomp protection unless a justified customization is required.
- Use AppArmor or SELinux where appropriate for the host environment.
- Protect the Docker daemon and its socket.
- Avoid unnecessary host bind mounts.
- Apply CPU and memory limits where appropriate.
- Review all privileged and host-sharing options.
- Keep the host kernel and container runtime maintained.
- Treat container isolation as one layer of a defense-in-depth security model.
22. Key Takeaways
• Docker uses Linux namespaces as a primary mechanism for container isolation.
• Namespaces provide different views of system resources to groups of processes.
• PID namespaces isolate process visibility and PID numbering.
• Network namespaces provide a separate network stack.
• Mount namespaces provide a separate filesystem mount view.
• UTS namespaces isolate hostname information.
• IPC namespaces isolate IPC resources.
• User namespaces can map container IDs to different host IDs.
• cgroups are complementary: they provide resource accounting and limiting.
• Rootless mode differs from userns-remap because the Docker daemon itself also runs without root.
• Namespace isolation is only one part of Docker security.
• Capabilities, seccomp, AppArmor/SELinux, daemon protection, filesystem controls, and host security
should be considered together.
Official References
Docker Engine security: https://docs.docker.com/engine/security/
Docker user namespace remapping: https://docs.docker.com/engine/security/userns-remap/
Docker Rootless mode: https://docs.docker.com/engine/security/rootless/
Docker seccomp profiles: https://docs.docker.com/engine/security/seccomp/
Docker AppArmor profiles: https://docs.docker.com/engine/security/apparmor/
Linux Kernel namespaces documentation: https://docs.kernel.org/admin-guide/namespaces/