Docker & Containerization

Chapter 1
Containerization Foundations and Terminology

Certificate in DevOps
Docker & Containerization   •   Certificate

Containerization Foundations and Terminology

Introduction and Context

Modern software systems must run reliably across laptops, development servers, test environments, data centres, and cloud platforms. Historically, applications were installed directly on operating systems. This approach often produced dependency conflicts: one application required a particular library version, while another required a different version. Differences in operating-system configuration, network settings, and hardware further increased the risk that software would work in one environment but fail in another.

Containerization addresses this problem by packaging an application with its executable code, libraries, configuration, and selected supporting files into a standard unit that can run consistently wherever a compatible container runtime is available. Containers do not eliminate all environmental dependencies, but they make those dependencies explicit and manageable.

Containerization is particularly important in DevOps because it supports repeatable builds, automated testing, rapid deployment, service isolation, and infrastructure automation. It also contributes to digital transformation by enabling organizations to modernize applications, scale services, and deliver software more frequently.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Distinguish traditional virtualization from operating-system-level containerization.
  2. Explain isolation, namespaces, and control groups.
  3. Describe layered filesystems and their effect on image storage and reuse.
  4. Explain portability, immutability, and the difference between images and containers.
  5. Describe the role of OCI standards and container runtimes.
  6. Relate containers to DevOps, microservices, cloud computing, and digital transformation.
  7. Identify important security, operational, and governance limitations of containers.

From Virtual Machines to Containers

Traditional virtualization

A virtual machine (VM) is a software-defined computer that includes a virtual hardware platform, a guest operating system, and application software. A hypervisor allocates physical resources such as processor time, memory, storage, and network interfaces to VMs. Type 1 hypervisors run directly on physical hardware, whereas Type 2 hypervisors run above a host operating system.

A VM provides strong separation because each guest operating system has its own kernel. This makes VMs useful when organizations need to run different operating systems on the same physical server or require a comparatively strong isolation boundary. However, each VM includes a complete operating system, which increases image size, startup time, patching requirements, and resource consumption.

Operating-system-level containerization

A container is an isolated process, or group of processes, that shares the host operating-system kernel. The container normally contains user-space components such as binaries, libraries, application code, and configuration, but not a separate kernel. A container runtime creates the process environment and applies isolation and resource controls.

The distinction is therefore fundamental: a VM virtualizes hardware, while a container generally virtualizes the operating-system environment experienced by a process. Containers are usually lighter and start faster than VMs, but they depend more directly on the host kernel and runtime security configuration.

FeatureVirtual machineContainer
Main abstractionVirtual hardwareIsolated process environment
KernelOne per guest VMGenerally shared with host
Typical startupLongerShorter
Image sizeOften largerOften smaller
Operating-system flexibilityCan run a different guest OSUsually requires kernel compatibility
Isolation boundaryHypervisor and guest OSKernel mechanisms and runtime
Typical useStrong isolation, legacy systems, mixed OS environmentsApplication packaging, microservices, rapid delivery

Neither technology is universally superior. Containers are frequently deployed inside VMs in cloud environments. The VM provides an infrastructure boundary, while containers provide application-level packaging and isolation.

Comparison of virtual machines and containers Virtual machines Containers Applications Guest libraries Guest operating systems Virtual hardware Hypervisor App A App B App C Libraries and filesystems Container runtime Shared host kernel
Comparison of virtual machines and containers
Figure: Comparison of virtual machines and containers

Figure: A VM includes a guest operating system, whereas containers generally share the host kernel.

Isolation: The Central Container Concept

Isolation means that a process sees a restricted, controlled view of system resources. A containerized process may have its own apparent hostname, process list, network interfaces, filesystem view, and user identifiers. This does not mean that the process is running on a separate computer. It means that the operating system presents a carefully scoped environment.

Isolation has several dimensions:

  • Process isolation: processes in one container are separated from processes in another.
  • Filesystem isolation: a container receives its own root filesystem view.
  • Network isolation: a container may have separate interfaces, addresses, routes, and ports.
  • User isolation: users and groups can be mapped so that a container’s root user does not necessarily correspond to unrestricted host privileges.
  • Resource isolation: CPU, memory, process counts, and I/O can be constrained.

Isolation is not identical to security. A misconfigured container may run with excessive privileges, mount sensitive host directories, or use an exposed service. Containers reduce accidental interference and improve organization, but they require secure configuration and a maintained host kernel.

Linux Namespaces

Namespaces are kernel mechanisms that partition global system resources so that processes receive different views of them. Linux container technologies commonly use several namespace types:

  • PID namespace: controls the process identifiers visible to a process. A process can appear to be process 1 inside its container even though it has a different identifier on the host.
  • Mount namespace: controls the filesystem mounts visible to processes.
  • Network namespace: provides separate network devices, routing tables, sockets, and firewall contexts.
  • UTS namespace: permits an isolated hostname and domain name.
  • IPC namespace: isolates inter-process communication resources.
  • User namespace: maps user and group identifiers between the container and host.
  • Cgroup namespace: presents a scoped view of control-group paths and resource organization.

Namespaces are a mechanism, not a complete container product. A runtime combines namespaces with filesystem construction, capability management, security policies, networking, and lifecycle operations.

Control Groups and Resource Governance

Linux control groups, commonly called cgroups, organize processes and control their consumption of resources. They can limit, prioritize, measure, or account for resources such as CPU, memory, block-device I/O, and the number of processes.

For example, a memory limit can prevent one workload from consuming all available memory on a host. A CPU quota can restrict the amount of processor time allocated to a container during a scheduling period. The exact behavior depends on the operating system and cgroup version, but the conceptual purpose is resource governance.

A resource limit is not the same as a performance guarantee. If several workloads compete for a saturated resource, a container with a limit may still perform poorly. Conversely, setting limits too low can cause application failure, including out-of-memory termination. Resource requests, limits, monitoring, and capacity planning must therefore be considered together.

Images, Containers, and Registries

A container image is a largely immutable package containing a filesystem representation and metadata needed to create a container. An image is not normally a running process. A container is a runtime instance created from an image, with a process, resource controls, networking, and a writable runtime layer.

A container registry stores and distributes images. Public registries may provide community or vendor images; private registries allow an organization to control access, retention, scanning, and provenance. Images are commonly identified by a repository name and tag, but a digest provides content-based identification. Tags are convenient labels and may be moved to point to different image content; digests are more suitable for reproducible deployment.

A useful lifecycle is:

  1. Define application source and dependency requirements.
  2. Build an image from a declarative specification.
  3. Test the image and its application behavior.
  4. Scan dependencies and image contents.
  5. Sign or otherwise attest to provenance where required.
  6. Push the image to an authorized registry.
  7. Pull the image into a deployment environment.
  8. Run, monitor, update, and eventually replace the container.

Layered Filesystems

Container images are commonly assembled from filesystem layers. Each build instruction may create or reference a layer. Layers are content-addressed and can be reused when identical content is required by multiple images. A runtime combines read-only image layers with a writable layer for the running container.

Layering provides storage efficiency and faster distribution. If ten images share a common base layer, that layer may be stored once on a host or registry. It also supports build caching. However, deleting a file in a later layer does not necessarily remove the bytes from an earlier layer; it usually creates a change that hides the earlier file. Sensitive data must therefore never be placed in an earlier image layer and then assumed to be securely removed later.

Good layering practices include using a trusted minimal base image, ordering infrequently changing instructions before frequently changing ones, removing temporary build material, and using multi-stage builds to exclude compilers and test tools from the production image. Minimal does not mean risk-free: a smaller image can reduce attack surface, but it still requires vulnerability management.

Portability and Its Boundaries

Portability is the ability to move an application workload between environments with limited modification. Containers improve portability by packaging user-space dependencies and standardizing the execution interface. A container image built on one developer workstation can often run on a test server or cloud host using a compatible runtime.

Portability has boundaries. A container depends on:

  • a compatible kernel and processor architecture;
  • a container runtime and image format;
  • external services such as databases, queues, identity providers, and DNS;
  • persistent storage and backup arrangements;
  • network policies and security capabilities;
  • environment-specific configuration and secrets.

A container image is therefore portable software packaging, not a complete portable infrastructure system. Configuration should be supplied at deployment time rather than embedded as environment-specific values. Secrets should be managed through an appropriate secret-management system, not committed to source code or image layers.

Immutability and Declarative Delivery

An immutable artifact is treated as a versioned object that is replaced rather than manually modified in place. Container immutability is a practice and design principle, not an absolute physical property. A running container has a writable layer unless it is deliberately made read-only, and an application may still write to external storage.

In an immutable delivery model, a change normally produces a new image. The deployment then replaces the old container with a new instance. This approach improves traceability and rollback because the desired version is explicit. It also discourages undocumented changes made through interactive shell sessions.

Immutability does not mean data should be discarded. State such as customer records should be stored in managed databases, persistent volumes, or other deliberately designed data services. Stateless application containers are easier to replace, scale, and recover, but stateful services can also be containerized when storage, backup, clustering, and operational expertise are properly addressed.

Open Container Initiative Standards

The Open Container Initiative (OCI) develops open specifications for container formats and runtimes. Its standards help prevent dependence on a single vendor and support interoperability across tools.

Important concepts include:

  • Image Specification: describes the structure and metadata of container images.
  • Runtime Specification: describes how a runtime should configure and execute a container from a bundle.
  • Distribution Specification: describes how content can be distributed through registries.

OCI specifications do not define every feature of a complete platform. Orchestration, build systems, service discovery, policy management, and developer workflows may be supplied by other technologies. OCI standardization provides a common foundation on which those systems can operate.

A high-level container stack may be understood as follows:

  1. A developer writes source code and an image build definition.
  2. A builder creates an OCI-compatible image.
  3. A registry distributes the image.
  4. A higher-level engine or orchestrator requests a workload.
  5. A runtime creates the process using kernel isolation and resource controls.
  6. Operating, security, networking, and storage systems support the workload.

Containers in DevOps

DevOps combines development and operations practices to improve delivery speed, reliability, feedback, and shared responsibility. Containers support this model in several ways.

Consistency: developers, testers, and production systems can use the same image artifact. This reduces, but does not eliminate, environment drift.

Automation: image builds, tests, vulnerability scans, registry publication, and deployments can be integrated into continuous integration and continuous delivery pipelines.

Fast feedback: containers can be created and removed efficiently for automated tests and temporary environments.

Service decomposition: independently deployable services can be packaged separately, although dividing an application into many services introduces operational complexity.

Scalability: multiple instances can be started when demand increases, provided that the application and platform support scaling.

Rollback: deployments can return to a previously approved image version, subject to database and compatibility considerations.

Containers do not automatically create DevOps. Effective DevOps also requires version control, automated testing, observability, collaboration, secure processes, and a culture of continuous improvement.

Containers and Digital Transformation

Digital transformation involves using digital technologies and redesigned processes to improve organizational performance, customer experience, and adaptability. Containers may contribute by enabling:

  • modernization of legacy applications through gradual decomposition;
  • more consistent delivery across hybrid and multi-cloud environments;
  • platform engineering and self-service development environments;
  • elastic deployment of web, data, and machine-learning services;
  • standardized security and operational controls.

The business value depends on the surrounding operating model. Containerizing an inefficient process without redesigning it may simply reproduce the inefficiency in a new package. Organizations must consider skills, governance, cost, architecture, vendor strategy, and support arrangements.

Illustrative Case: An Online Retail Service

Background

An online retailer operates a web application installed directly on several long-lived servers. The application depends on a particular runtime and library set. Releases occur quarterly because installation is manual and testing environments differ from production.

Problem

A new release works on a developer’s workstation but fails in production because a system library is older. Operations staff also discover that one service consumes excessive memory and affects unrelated applications. Rollback requires restoring server files from a backup.

Analysis

The retailer has two related problems: dependency inconsistency and weak workload isolation. A full VM strategy could separate applications, but the organization also wants faster test creation and more frequent releases. Containers are a suitable packaging mechanism, provided that security, persistent data, and operational monitoring are addressed.

Approach

The team creates a reproducible image containing the application runtime and required user-space libraries. The image is built in a CI pipeline, tested automatically, scanned for known vulnerabilities, and stored in a private registry. Production configuration is injected at deployment time. Each service receives appropriate CPU and memory controls, and logs and metrics are sent to centralized systems. Customer data remains in a managed database rather than in the container’s writable layer.

The deployment uses immutable image references, preferably digests, and replaces containers during release. The host operating system and runtime are patched through a defined maintenance process. The team also applies least privilege, avoids unnecessary host mounts, and uses non-root execution where practical.

Outcome

The same approved image is used in testing and production. Releases become smaller and more frequent, and an unhealthy service is less likely to exhaust the resources available to unrelated services. Rollback becomes simpler because the previous image remains available. Nevertheless, the retailer still must manage database schema compatibility, registry availability, vulnerability remediation, monitoring, and platform skills.

Learning points

  1. Containers address packaging and process-isolation problems, not every operational problem.
  2. Reproducible images are more valuable than manually configured containers.
  3. Persistent data requires an explicit storage design.
  4. Resource controls reduce interference but do not replace capacity planning.
  5. Security must include the image supply chain, runtime configuration, host, network, and application.

Challenges, Risks, and Governance

Security

The shared-kernel model means a kernel vulnerability may affect multiple containers. Images may contain vulnerable packages, outdated software, malware, or undisclosed licensing obligations. Registries and build systems are part of the software supply chain and must be protected.

Basic controls include trusted base images, regular rebuilding, vulnerability scanning, signed or attested artifacts, least-privilege execution, restricted Linux capabilities, read-only filesystems where feasible, network segmentation, secure secrets management, and host patching. Scanning results must be interpreted rather than treated as automatic proof of safety: a vulnerability’s exploitability and application exposure matter.

Operations

Containers are ephemeral by design, so administrators should not depend on manual changes inside a running instance. Logs, metrics, traces, configuration, and data must be integrated with external systems. Teams need policies for image retention, naming, versioning, incident response, and end-of-life.

Compliance and ethics

Organizations may have legal obligations concerning personal data, auditability, software licensing, location of data, and access control. Images can unintentionally include credentials or personal information. Automated deployment does not remove accountability; organizations must be able to identify what was deployed, by whom, from which source, and under which approval process.

Architectural limitations

Containers add a platform layer. They may increase complexity when teams introduce orchestration, service meshes, distributed tracing, and multiple registries without sufficient need or expertise. A simple application may be better served by a conventional deployment or a managed platform. Technology selection should follow requirements rather than fashion.

Contemporary Developments

Container technology is increasingly used with managed cloud services, serverless container platforms, edge computing, and Kubernetes-based orchestration. Rootless containers and user namespaces can reduce the consequences of runtime compromise. Software supply-chain frameworks increasingly emphasize provenance, artifact signing, dependency transparency, and policy enforcement.

Containers also support machine-learning workflows by packaging libraries, model-serving code, and inference environments. However, large model files, accelerator drivers, data governance, and performance requirements introduce additional considerations. Artificial intelligence does not change the foundational distinction between an image, a running container, a runtime, and the host kernel.

Best-Practice Foundations

For introductory container work, the following practices are sound:

  1. Use version-controlled, reproducible image definitions.
  2. Prefer small, trusted, maintained base images.
  3. Pin important dependencies and use immutable image digests in controlled deployments.
  4. Do not store secrets in source code or image layers.
  5. Run processes with the least privilege practical.
  6. Separate application images from persistent data.
  7. Define health checks, resource controls, and logging behavior.
  8. Scan, update, and rebuild images regularly.
  9. Test the exact artifact intended for release.
  10. Document runtime, kernel, storage, network, and recovery assumptions.
  11. Monitor both application behavior and platform resources.
  12. Use containers because they solve a demonstrated problem, not merely because they are fashionable.

Chapter Summary

Containerization packages application code and user-space dependencies into portable images that can be instantiated as isolated processes. Unlike virtual machines, containers generally share the host kernel, which makes them lightweight and fast but creates kernel-compatibility and security considerations. Namespaces provide scoped views of processes, filesystems, networks, users, and related resources. Control groups govern resource consumption and help prevent one workload from overwhelming others.

Layered filesystems improve reuse and distribution efficiency, while images and containers provide a useful distinction between immutable artifacts and running instances. Portability is valuable but conditional on compatible kernels, runtimes, architectures, external services, storage, and configuration. OCI specifications promote interoperability among image, runtime, and distribution tools.

In DevOps, containers support repeatable builds, automated delivery, testing, scaling, and rollback. In digital transformation, they can enable modernization and standardization, but their value depends on architecture, governance, security, skills, and operating practices. Containers are not a complete security boundary or a substitute for sound engineering. Their successful use requires disciplined image construction, least privilege, supply-chain protection, observability, resource management, and explicit treatment of persistent data.

Key Terms

Container: An isolated process environment created from an image.

Container image: A packaged, versioned filesystem and metadata used to create containers.

Container runtime: Software that creates and executes containers.

Virtual machine: A software-defined computer containing virtual hardware and a guest operating system.

Hypervisor: Software that creates and manages virtual machines.

Kernel: The core operating-system component that manages hardware and system resources.

Isolation: Restriction of a process’s view and access to system resources.

Namespace: A kernel mechanism that provides an isolated view of a system resource.

Control group: A mechanism for limiting, measuring, and prioritizing resource use by processes.

Registry: A service that stores and distributes container images.

Layer: A reusable filesystem change contributing to an image.

Writable layer: The runtime storage layer in which a container can record changes.

Portability: The ability to run software across environments with limited modification.

Immutability: The practice of replacing versioned artifacts rather than modifying them in place.

OCI: The Open Container Initiative, which develops open container specifications.

Microservice: An independently deployable service focused on a relatively bounded capability.

Image digest: A content-derived identifier for a specific image artifact.

Supply chain: The people, processes, tools, dependencies, and artifacts involved in producing and delivering software.

Orchestration: Automated scheduling, networking, scaling, and lifecycle management of workloads.

Least privilege: Granting only the permissions required for a task.

Review Questions

Short Answer Questions

  1. What is the principal difference between a virtual machine and a container?
  2. What purpose do Linux namespaces serve?
  3. How do control groups support container operations?
  4. Why are image digests generally more reliable than mutable tags for deployment identification?
  5. What is the relationship between a container image and a running container?

Long Answer Questions

  1. Explain how namespaces and control groups work together to create an isolated container environment.
  2. Compare the benefits and limitations of containers and virtual machines in an enterprise environment.
  3. Explain how layered filesystems improve image distribution and identify one security risk associated with layers.
  4. Discuss how containerization supports continuous integration and continuous delivery.
  5. Explain why container portability is useful but not unlimited.

Analytical / Application Questions

  1. A team stores database files inside a container’s writable layer and loses them when the container is replaced. Analyze the design error and propose a more appropriate storage approach.
  2. An application container repeatedly consumes all available memory on a host. Recommend a combination of control, monitoring, and architectural actions, and explain why a single memory limit may not solve the complete problem.
  3. An organization wants to place an untrusted workload beside sensitive services in containers sharing one host kernel. Evaluate the isolation and governance risks and recommend whether additional VM or platform boundaries should be considered.

Multiple Choice Questions with Answers

Question 1

Which statement best distinguishes a container from a virtual machine?

A. A container normally shares the host kernel, while a virtual machine includes a guest operating system.

B. A container always includes a complete guest operating system, while a virtual machine does not.

C. A virtual machine cannot isolate processes, while a container can isolate hardware.

D. A container requires a separate physical server for each application.

Correct Answer: A. A container normally shares the host kernel, while a virtual machine includes a guest operating system.

Question 2

Which Linux mechanism provides a container with a separate view of processes or network interfaces?

A. Control groups

B. Namespaces

C. Image registries

D. Hypervisors

Correct Answer: B. Namespaces

Question 3

What is the primary purpose of control groups?

A. To build image layers

B. To provide DNS names for registries

C. To limit and account for resource consumption by processes

D. To replace the host operating-system kernel

Correct Answer: C. To limit and account for resource consumption by processes

Question 4

What is a container image?

A. A running process with a temporary network address

B. A packaged filesystem and metadata used to create containers

C. A physical server containing multiple applications

D. A database backup created by the container runtime

Correct Answer: B. A packaged filesystem and metadata used to create containers

Question 5

Why are layered filesystems useful?

A. They allow identical filesystem content to be reused across images.

B. They guarantee that all containers have unlimited storage.

C. They remove the need to patch base images.

D. They prevent applications from writing any data.

Correct Answer: A. They allow identical filesystem content to be reused across images.

Question 6

Which statement about container portability is most accurate?

A. A container removes all dependencies on hardware and operating systems.

B. A container can run without a compatible kernel or runtime.

C. A container improves portability but still depends on compatible platforms and external services.

D. A container automatically migrates persistent data between clouds.

Correct Answer: C. A container improves portability but still depends on compatible platforms and external services.

Question 7

Which practice best supports immutable delivery?

A. Editing production containers manually after deployment

B. Building a new versioned image and replacing the old container

C. Embedding passwords in the image for convenience

D. Using an untracked mutable tag for every release

Correct Answer: B. Building a new versioned image and replacing the old container

Question 8

What is the main role of the OCI Runtime Specification?

A. It defines how a runtime configures and executes a container.

B. It specifies the business logic of microservices.

C. It replaces all cloud orchestration platforms.

D. It defines application database schemas.

Correct Answer: A. It defines how a runtime configures and executes a container.

Question 9

Which practice is most appropriate for persistent customer data?

A. Store it only in the container’s temporary writable layer.

B. Store it in an external database or deliberately managed persistent volume.

C. Place it in a build cache layer and delete it later.

D. Store it in an image tag name.

Correct Answer: B. Store it in an external database or deliberately managed persistent volume.

Question 10

Which statement about container security is correct?

A. Containers are automatically a complete security boundary.

B. Image scanning eliminates the need to patch the host kernel.

C. Least privilege, trusted images, host patching, and runtime controls are all relevant security measures.

D. Running as root inside a container is always harmless because the process is isolated.

Correct Answer: C. Least privilege, trusted images, host patching, and runtime controls are all relevant security measures.

Docker & Containerization
Chapter 1 of 13