Appearance

Containers are processes

Separate Linux process isolation from resource control and virtual machines.

What you will understand

  • Explain why a container shares its host kernel
  • Distinguish namespaces from cgroups
  • Predict what survives a container restart

Mental model: a process with boundaries

A container is a running process, or a small process tree, started with an isolated view of parts of its host. It is not a miniature computer with a separately booted kernel. On a Linux host, two ordinary Linux containers use the same host kernel while seeing different filesystem roots, network interfaces, or process IDs. The image provides application files and dependencies; the runtime arranges isolation and starts the configured executable. When that executable exits, the container stops. Keeping an empty terminal open is not the goal; keeping the intended application process healthy is.

A virtual machine places a guest operating system behind a virtual hardware boundary. Containers usually provide a lighter process boundary. Neither description means arbitrary untrusted code is harmless. Kernel vulnerabilities, privileged configuration, host mounts, and excessive capabilities affect isolation. On a macOS or Windows development laptop, a Linux container commonly runs inside a Linux virtual machine. The relevant shared kernel is that Linux VM’s kernel, not the laptop’s native kernel.

Linux namespaces change what a process can see. A PID namespace can make a process appear as PID 1 inside its container. A mount namespace gives it a particular filesystem view. A network namespace supplies interfaces, routes, and port bindings. These are operating-system namespaces; later, Kubernetes namespaces will organize API objects and will not create these kernel boundaries by themselves.

One kernel, separate views

Follow the runtime creating a Linux process namespace boundary.

Cluster viewStep 1 of 3
Start from the hostThe host kernel runs processes. A container runtime asks that kernel to create the isolation needed for the configured executable.. Linux host kernel, active. Container runtime, active. Process A, idleLinux host kernel
Linux host kernelIn focus
Container runtime
Container runtimeIn focus
Process A
Process AContext
Linux host kernelIn focus
Container runtimeIn focus
Process AContext
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: host access weakens isolation
Start from the host

The host kernel runs processes. A container runtime asks that kernel to create the isolation needed for the configured executable.

Read the complete visual sequence
  1. Start from the host

    The host kernel runs processes. A container runtime asks that kernel to create the isolation needed for the configured executable.

  2. Create a private view

    Process A sees its own PID and mount namespaces. Another process can see different IDs and filesystem roots while still calling the same kernel.

  3. Stop the application

    When A exits, its container stops. B can keep running; no guest operating system needs to be shut down.

Failure: host access weakens isolation

Failure: host access weakens isolation

  1. A privileged choice

    A container started with unnecessary host access no longer has the intended restricted view.

  2. The shared boundary matters

    A writable host mount exposes real host files; the image filesystem is not a protective copy of that mount.

  3. Reduce access

    Use only necessary mounts and privileges. Namespace isolation is one mechanism, not a complete trust policy.

About this model

Two Linux containers share one Linux host; sandboxed runtimes are outside this diagram.

Walkthrough: visibility and consumption are different

Control groups, commonly called cgroups, account for and constrain resource consumption by groups of processes. A namespace can hide other processes without preventing this process from consuming CPU or memory. A memory constraint can limit consumption without changing which processes are visible. These mechanisms answer separate questions: “what can this process see?” and “how much may it consume?”

The following optional Docker exercise needs Docker installed and a working Linux container backend. Kubernetes does not require the Docker CLI; this is a familiar way to inspect the underlying ideas. The image tag is a convenient training choice, not a reproducible production identifier.

# The foreground executable is a shell running a finite command.
docker run --name process-demo --memory 64m --cpus 0.5 \
  alpine:3.20 sh -c 'echo "container PID: $$"; sleep 300'
# In another terminal, inspect that process from inside its boundary.
docker exec process-demo ps
# Resource reporting comes from runtime/host accounting.
docker stats --no-stream process-demo
# Stop the demo and remove its container metadata and writable layer.
docker stop process-demo
docker rm process-demo

The process listing should be much smaller than the host’s process listing. Reported memory includes actual usage and accounting details; setting a 64 MiB limit does not preallocate 64 MiB or guarantee that all of it is available to application data. A CPU limit constrains CPU time over accounting intervals. It does not reserve half of one particular physical core. Kubernetes later expresses requests and limits, and the node runtime translates relevant settings into operating-system controls.

Visibility is not a resource limit

Contrast namespaces with cgroup accounting and enforcement.

Policy viewStep 1 of 3
An isolated process can allocateA PID namespace changes visible process IDs. It does not impose a memory budget.. Isolated process, active. Host memory, activeIsolated process
Isolated processIn focus
Host memory
Host memoryIn focus
Isolated processIn focus
Host memoryIn focus
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: allocate past the limit
An isolated process can allocate

A PID namespace changes visible process IDs. It does not impose a memory budget.

Read the complete visual sequence
  1. An isolated process can allocate

    A PID namespace changes visible process IDs. It does not impose a memory budget.

  2. Apply a cgroup boundary

    The runtime places the process in a cgroup. Memory usage is accounted against the configured 64 MiB maximum.

  3. Observe both mechanisms

    The process has a private view and bounded consumption. Neither creates separate physical memory or a separate kernel.

Failure: allocate past the limit

Failure: allocate past the limit

  1. Usage approaches maximum

    The application allocates memory inside its cgroup. The host may have free memory while this cgroup has no remaining allowance.

  2. OOM can terminate a process

    If the constrained group cannot satisfy allocation, an OOM kill can end the application. Namespace isolation does not change this limit.

  3. Investigate, then resize

    Inspect memory demand and termination evidence. Increasing a limit without understanding demand can merely move the pressure to the host.

About this model

A Linux node uses cgroup v2 memory.max; reclaim, temporary limit overshoot, and exact OOM victim selection are simplified.

Practice: reason about the writable layer

Start another disposable container, create a file under /tmp, and inspect it while that same container exists. Then remove the container and create a new one from the same image. The new instance starts from image contents, so your added file is absent. Distinguish restarting the same Docker container, which normally retains its writable layer, from creating a replacement container. In Kubernetes, a restarted container receives a fresh container filesystem; a mounted volume follows its own lifetime rules. Never assume the image will acquire files written by a running process.

Predict each observation before you run commands. Record the configured executable, its exit behavior, the resource limits, and the location of state. These four facts explain many later Pod failures without requiring any cluster machinery.

Pitfalls

A process that handles signals poorly can delay termination, especially when a shell wraps the real executable. Prefer an executable that receives termination signals correctly, and use exec-form entrypoints when authoring images. A process running as root inside a container is also not automatically safe because it has an isolated filesystem view. Use deliberate security configuration rather than treating “containerized” as a permission model.

Check your understanding

If a container cannot see other processes, can it still exhaust shared host resources?

Yes. Process visibility comes from namespaces; resource accounting and constraints come from cgroups and other host policies. Without appropriate constraints, an isolated process can still compete heavily for CPU or memory. Isolation of a view is not a resource reservation. If a memory limit is exceeded, the kernel may kill processes in the constrained group; it does not create a larger machine.

Continue with images and compare an immutable starting filesystem to a running process’s writable changes. Use the module lab to connect those boundaries to ports and requests.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.