Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › cgroups

Docker Internals Explained: How Namespaces, Cgroups, and Layered Filesystems Work

By Freedom251 Team · · 9 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Docker container is an ordinary process (or process tree) running with restricted, isolated views of the Linux system. Namespaces separate what that process can see, cgroups control how many resources it can consume, and a container filesystem combines read-only image layers with a private writable layer. Docker does not boot a separate guest kernel for each Linux container.

The daemon turns your container configuration into an OCI runtime invocation through containerd; Docker documents runc as its default runtime. The runtime asks the Linux kernel to create the namespaces and cgroups, then mounts the image layers and writable layer. This architecture explains both the speed of containers and their limits: isolation is strong but configurable, and data written only to a container layer disappears when that container is removed.

As an Amazon Associate I earn from qualifying purchases.

What a Docker container actually is

Docker packages an application and its user-space dependencies, then starts the application as an isolated Linux process. The host kernel still performs scheduling, memory management, networking, system calls and filesystem operations. A container therefore has a separate process environment, not a private operating system kernel.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker’s documentation describes namespaces as the isolated workspace for a container. A process in a container can receive its own view of process identifiers, mounts, networking, host naming and other kernel resources, while the host retains the underlying resources. The exact boundary depends on the namespaces, capabilities, mounts and other options selected for the container.

Isolation is not the same as invisibility

Namespaces prevent ordinary processes in one namespace from seeing or controlling resources in another as if they were on the same system. They do not make a container an independent machine. Containers can communicate over networks that Docker configures, and privileged settings can deliberately widen access. Docker’s security guidance treats namespaces and control groups as part of a larger security model that also includes the daemon, Linux capabilities, container configuration and kernel hardening.

From the Docker command to the Linux kernel

When you create or start a container, several components pass the request down the stack:

  1. Docker client and daemon: The CLI or an API request describes the image, command, mounts, environment, network and limits. The daemon validates the request and manages the container lifecycle.
  2. containerd: Docker invokes an OCI-compliant runtime through containerd. This separates image and lifecycle management from the low-level operation of entering namespaces and applying kernel settings.
  3. OCI runtime: Docker documents runc as the default runtime. It receives a runtime bundle describing the root filesystem, namespaces, mounts, credentials and limits.
  4. Linux kernel: The runtime creates namespaces, attaches the process to cgroups, configures mounts and networking, and starts the container’s initial process.

Docker is therefore the policy and management layer; it does not reimplement namespaces or cgroups. The kernel supplies those primitives, while the daemon and runtime assemble them into the container you requested. The runtime path is documented in the dockerd reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Namespaces: separate views of shared resources

A namespace changes what a process can see or address. The same host can run multiple containers whose processes use overlapping identifiers or names because each process is looking through a different namespace view.

Process and host identity

With a process namespace, a container can have its own process-number space. The first process started in that namespace appears as the container’s initial process, while the host still tracks it with a host-level process ID. Similar isolation can apply to the host name and domain name presented to processes.

Mount and filesystem view

A mount namespace gives the container its own arrangement of mounted filesystems. Docker can mount the image’s merged root filesystem there, add temporary filesystems, expose selected host paths and hide paths that should not be visible. A mount namespace does not by itself decide which files are writable; the storage driver and mount options determine that.

Network view

A network namespace gives a container its own interfaces, routes, ports and firewall context. Docker then connects that namespace to a bridge, host network or another configured network. Because networking is intentionally configurable, namespace isolation does not prevent communication when a Docker network permits it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

User and capability boundaries

User namespaces can map container user IDs to different host IDs, reducing the effect of a process that escapes its intended permissions. Capabilities further divide the traditionally all-powerful root account into smaller privileges. Running as container root, adding capabilities or using host namespaces changes the security boundary; those choices should be treated as deployment decisions, not harmless defaults.

Cgroups: controlling consumption rather than visibility

Control groups (cgroups) answer a different question from namespaces. Namespaces determine what a process can see; cgroups determine how the kernel accounts for and limits groups of processes. Docker creates or joins a cgroup for a container when it starts, as described in its security documentation.

Depending on the host kernel and Docker configuration, cgroups can apply limits or accounting to resources such as CPU time, memory, process counts and block-I/O activity. A memory limit can cause allocation failures or an out-of-memory kill when the group exceeds its allowance; a CPU limit can constrain scheduling time rather than hide CPUs from the process. These are enforcement mechanisms, not performance guarantees: host contention, kernel behavior and the selected cgroup version still matter.

Why namespaces and cgroups are paired

Isolation without resource control would let one visible process consume disproportionate host resources. Resource control without isolation would leave processes sharing the same global view. Docker combines both so an application can have a private-looking environment while the host retains authority over scheduling, accounting and termination.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How image layers become a container filesystem

A Docker image is assembled from filesystem layers. Each Dockerfile instruction normally contributes a layer, and those layers are reusable read-only building blocks. Two containers created from the same image can share unchanged image data instead of storing duplicate copies.

At container creation, Docker adds a container-specific writable layer above the image layers. The process sees one merged directory tree, but the storage backend keeps the lower image content separate from the upper writable area. Reads can come from a lower layer when the file has not changed; new files and modifications are recorded in the writable layer.

Copy-on-write in the classic overlay2 model

On Linux installations using the classic overlay2 storage driver, image layers are read-only lower directories and the container layer is the upper directory. OverlayFS presents their union as one mount. If a process modifies a file that exists only in a lower layer, overlay2 performs a copy-up: it copies the file into the upper layer, and subsequent writes affect that copy. The shared image layer remains unchanged. Docker explains these details in its OverlayFS storage-driver documentation.

Copy-up means a small edit can require copying the entire underlying file into the writable layer. That behavior is one reason Docker advises keeping write-heavy application data in volumes rather than repeatedly modifying large files in the container layer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What survives when a container stops or is deleted?

Stopping a container leaves its writable layer available for a later restart. Removing the container removes that layer. Any change stored only there—generated files, package-manager caches, database pages or application uploads—is lost with the container. The image layers are unaffected because they are shared, read-only inputs.

Data that must outlive a container belongs in persistent storage. Docker volumes are the normal mechanism for application data that should survive container replacement. A volume is managed separately from the container’s writable layer, so deleting and recreating the container does not delete the volume unless you explicitly remove it. This separation also avoids making a storage driver’s copy-on-write layer carry sustained write traffic.

A simple lifecycle example

  1. An image supplies read-only files such as the application binary and base libraries.
  2. The container starts with a private writable layer and may receive a volume at an application data path.
  3. The application reads code from the image, writes temporary state to the writable layer and writes durable records to the volume.
  4. When the container is removed, temporary state in the writable layer disappears; the volume remains available to the replacement container.

Storage drivers and the Docker Engine 29.0 change

Layer mechanics depend on the storage backend and Docker Engine version. Docker’s current storage-driver selection guidance says fresh installations of Docker Engine 29.0 and later use the containerd image store by default. An installation upgraded from an earlier release can continue using a classic storage driver, so the same version number does not guarantee the same on-disk layout.

With the containerd image store, Docker’s daemon configuration documentation places image contents and container snapshots under /var/lib/containerd; other daemon data remains under /var/lib/docker. Do not assume that every current host stores image layers in /var/lib/docker/overlay2.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Backend or approach Role and characteristics When it fits Important qualification
Containerd image store and snapshotters Default for fresh Docker Engine 29.0+ installations; manages image content and container snapshots. New installations following the current Docker default. Upgraded installations may still use a classic driver; snapshotter behavior varies by configuration.
overlay2 Classic Linux union-filesystem driver with read-only lower layers, an upper writable layer and copy-up behavior. Broadly compatible Linux hosts that retain the classic storage-driver model. It is not the universal layout on fresh 29.0+ installations.
fuse-overlayfs Userspace OverlayFS implementation available for certain rootless hosts. Rootless environments where kernel OverlayFS support or permissions are unsuitable. Compatibility and performance depend on the host and workload.
btrfs or zfs Filesystem-integrated storage options with their own snapshot, maintenance and operational characteristics. Hosts deliberately built and administered around those filesystems. They require additional setup and ongoing filesystem-specific maintenance.
vfs Does not provide copy-on-write layer sharing. Testing or hosts without a suitable copy-on-write implementation. Higher storage use and slower duplication make it unsuitable for many production workloads.

The table describes Docker’s documented options, not a universal performance ranking. The appropriate choice depends on the engine version, whether the containerd image store is enabled, the Linux kernel and backing filesystem, stability requirements, and whether the data is mostly read-oriented or write-heavy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing the right place for each kind of data

Use image layers for immutable application content: base operating-system files, installed dependencies and release artifacts. Use the container writable layer for disposable runtime changes such as temporary files or a short-lived cache. Use volumes for databases, queues, uploads and other state that must survive replacement, especially when writes are frequent.

  • Mostly reads, infrequent writes: Layer sharing can be efficient, but monitor copy-up when files are modified.
  • Large or write-heavy files: Put them in a volume instead of the container layer to avoid repeated copy-up and to preserve data across recreation.
  • Rootless deployment: Check whether the selected driver supports the host’s kernel and permissions; fuse-overlayfs may be an option.
  • Existing production host: Identify the active image store and driver before moving data or interpreting disk usage. A fresh-install default does not describe every upgraded daemon.

Common misconceptions and failure modes

“A container is a lightweight virtual machine.”

It is isolated processes sharing the host kernel, not a second kernel. A workload that requires a different kernel, kernel modules or a stronger machine boundary needs a virtualization design rather than ordinary container isolation.

“Deleting a container deletes the image.”

Image layers are separate, reusable inputs. Removing a container removes its writable layer; the image remains unless you remove it independently.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The writable layer is permanent storage.”

It lasts only as long as that container. Recreating a container from the same image creates a new writable layer, so unmounted application data is not restored.

“Every Docker host has an overlay2 directory.”

That assumption is wrong on fresh Docker Engine 29.0+ installations using the containerd image store, and it can also be wrong when another driver is configured. Inspect the daemon’s active storage configuration instead of relying on a path copied from another host.

“Namespaces alone provide complete security.”

Security also depends on capabilities, daemon exposure, mounts, network configuration, kernel patches and whether host namespaces or privileged options are enabled. Treat a container as an isolation boundary that must be configured and hardened, not as an automatic replacement for host security.

A practical mental model

Think of a container startup as four coordinated operations: create separate kernel views with namespaces; attach the process to cgroups for accounting and limits; mount a merged root filesystem from image layers plus a writable layer; and start the application through the OCI runtime. The image is the reusable, read-only template. The writable layer is disposable working space. A volume is the separately managed location for state that must survive.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That model remains valid across Docker storage backends, while the implementation details—such as OverlayFS copy-up and the location of on-disk snapshots—depend on the active driver and engine version. Check those details whenever filesystem behavior, disk usage or persistence matters.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

cgroupscontainerdcontainersDockerLinuxnamespacesOverlayFSstorage drivers

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.