Chapter 1
Containerization Foundations and Industry Context
Diploma in DevOps
Containerization with Docker
•
Diploma
Containerization Foundations and Industry Context
Introduction and Context
Software systems have traditionally been deployed directly on physical servers or inside virtual machines. Both approaches can support reliable services, but they often create difficulties when applications move between developers’ computers, testing environments, data centres, and cloud platforms. Differences in operating-system libraries, configuration files, networking, security policies, and hardware frequently produce the familiar problem: an application works in one environment but fails in another.
Containerization addresses this problem by packaging an application together with its executable code, libraries, configuration, and selected system dependencies. The package can then run consistently on any compatible host that provides a container runtime. Docker is the most widely recognised platform for building, distributing, and running such containers, although containerization as a technology is broader than Docker itself.
Containers are important to DevOps because they connect software development and operations. Developers can define an application environment as code, while operations teams can deploy the same artefact through automated pipelines. Containers also support microservices, elastic cloud deployment, continuous delivery, and reproducible testing. However, they are not a universal solution. Their security, persistence, networking, observability, cost, and operational complexity must be managed carefully.
Learning Objectives
By the end of this chapter, you should be able to:
distinguish physical machines, virtual machines, and containers;
explain portability, immutability, isolation, and reproducibility;
describe Docker’s principal objects and terminology;
relate containers to microservices and cloud-native architecture;
evaluate the benefits and limitations of containerization;
identify governance, security, and operational responsibilities; and
explain how containers contribute to digital transformation.
From Physical Servers to Virtual Machines
A physical server provides computing resources such as processor capacity, memory, storage, and network interfaces. Traditionally, one major application was installed directly onto the server’s operating system. This model can be efficient, but applications may compete for resources and may require incompatible versions of libraries or runtime components.
Virtualization introduces a software layer called a hypervisor. The hypervisor presents virtual hardware to several guest operating systems. Each virtual machine (VM) includes a complete guest operating system, its libraries, and its applications. A type 1 hypervisor runs directly on hardware, whereas a type 2 hypervisor runs above a host operating system.
Virtual machines provide strong isolation and allow different operating systems to run on the same physical host. Their principal cost is duplication: every VM contains its own operating-system kernel and usually a substantial collection of system files. This increases image size, startup time, patching effort, and memory consumption.
A container is an isolated process, or group of processes, that shares the host operating-system kernel while maintaining separated views of resources. On Linux, container engines commonly use kernel mechanisms such as namespaces for isolation and control groups (cgroups) for resource accounting and limits. Windows containers use corresponding operating-system facilities.
Unlike a VM, a container does not normally contain a complete independent kernel. A container image contains user-space files, application code, libraries, and metadata. The runtime starts the application as a process on the host kernel. This explains why containers are generally lightweight and quick to start, while also explaining why kernel compatibility and host security remain important.
Virtualization and Containerization Compared
Characteristic
Virtual machine
Container
Main isolation boundary
Virtual hardware and guest OS
Process and operating-system facilities
Kernel
Each VM normally has its own kernel
Shared with the host or compatible VM
Typical size
Larger
Smaller
Startup
Usually slower
Usually faster
Operating-system flexibility
Can run different guest OSs
Constrained by kernel and image compatibility
Resource overhead
Higher
Lower, though not zero
Typical use
Strong isolation, legacy systems, OS diversity
Packaging, services, CI/CD, scalable applications
The distinction should not be overstated. Containers are often run inside VMs in public clouds. In that arrangement, the VM provides a hardware-virtualization boundary and containers provide application-level packaging and isolation within the VM.
Comparison of virtual machine and container architectures
Figure: Comparison of virtual machine and container architectures
Figure: Simplified architectural comparison of virtual machines and containers.
Foundational Properties of Containers
Portability
Portability is the ability to move an application between environments with minimal modification. A container image records much of the application’s user-space environment, reducing dependence on the host’s installed packages. Portability is not absolute: CPU architecture, kernel features, device access, filesystem behaviour, network policy, secrets, storage systems, and external services can still vary.
A practical definition is therefore conditional portability: an image is portable across hosts that support the required architecture, runtime, kernel features, permissions, and external interfaces. Teams should test images on the environments in which they will operate rather than assuming that an image runs identically everywhere.
Immutability
An immutable artefact is treated as a fixed version after it has been built. Instead of modifying a running container manually, an updated image is built, tested, and deployed. This creates traceability and reduces configuration drift. Immutability does not mean that data never changes. Databases, uploads, logs, and queues are mutable state and should normally be stored outside the disposable container filesystem through managed services or carefully designed volumes.
Reproducibility
Reproducibility means that the same source and declared inputs produce substantially the same result. Dockerfiles, locked dependency versions, source-control history, automated builds, and content-addressed image digests contribute to reproducibility. It can be weakened by unpinned base-image tags, downloading unverified dependencies during a build, timestamps, random build steps, or reliance on external repositories that later change.
Isolation
Containers isolate processes, filesystems, users, network interfaces, and resource usage. Isolation is a risk-reduction mechanism, not proof of perfect separation. A privileged container, an exposed host socket, excessive Linux capabilities, a kernel vulnerability, or insecure mounted files can undermine the boundary. Security requires defence in depth.
Ephemerality
A container is commonly designed to be replaceable. If a process fails, an orchestrator can create a new instance from the same image. Ephemerality encourages stateless service design, externalized configuration, health checks, and automated recovery. It does not imply that every application must be stateless; stateful workloads require deliberate storage, identity, backup, and failover designs.
Docker Terminology and Object Model
Docker uses a client–daemon architecture in many installations. The Docker CLI sends requests to a Docker daemon, which manages images, containers, networks, and volumes. Docker Desktop packages major components for desktop operating systems. In other environments, a container runtime such as containerd or CRI-O may be used without the Docker daemon.
Important terms include:
Image: A read-only, versioned package containing application files, metadata, and references to filesystem layers.
Layer: A filesystem change that contributes to an image. Reusing unchanged layers can improve build and transfer efficiency.
Dockerfile: A text file containing instructions for constructing an image.
Container: A runtime instance of an image, with a writable container layer unless storage is explicitly externalized.
Registry: A service that stores and distributes images. It may be public or private.
Repository: A named collection of related image versions in a registry.
Tag: A human-readable label such as 1.4 or stable. Tags can be moved and should not be treated as immutable identifiers.
Digest: A content-derived identifier, commonly represented by a cryptographic hash, that identifies a particular image manifest.
Volume: Docker-managed persistent storage mounted into containers.
Bind mount: A host path mounted into a container; useful but more dependent on host layout and permissions.
Network: A virtual connectivity mechanism that enables containers to communicate with one another and with external systems.
Compose: A declarative format and tool for defining multi-container applications, networks, volumes, and configuration.
Entrypoint and command: Metadata controlling the process launched when a container starts.
The usual lifecycle is: write source and a Dockerfile, build an image, test it, tag it, scan it, push it to a registry, pull it onto a deployment host, and run it as a container. In professional environments, this lifecycle is automated in a continuous integration and continuous delivery pipeline.
Microservices and Cloud-Native Principles
A monolith packages many business capabilities into one deployable unit. A microservice architecture divides a system into relatively small services aligned with business capabilities. Each service can be developed, tested, deployed, and scaled independently, provided that its interfaces and data ownership are well designed.
Containers are a convenient packaging unit for microservices because they provide consistent runtime environments and fit automated deployment systems. Nevertheless, containerization does not create microservices. A monolithic application can run in one container, and poorly designed microservices can create excessive network calls, duplicated code, difficult debugging, and operational overhead.
Cloud-native systems generally emphasize:
Automation: infrastructure and delivery processes are expressed as code.
Elasticity: capacity can be adjusted in response to demand.
Resilience: failure is expected and recovery is automated.
Observability: logs, metrics, traces, and health information support diagnosis.
Loose coupling: services communicate through explicit, versioned interfaces.
Managed services: suitable databases, queues, and platforms are consumed rather than unnecessarily operated internally.
Security by design: identity, least privilege, supply-chain assurance, and policy are embedded in delivery.
These principles are related but not synonymous with containers. A cloud-native application may use serverless functions or managed platforms, while a containerized application may still be deployed manually on a single server.
Benefits and Limitations
Benefits
Containers can reduce environment inconsistency, accelerate startup, support dense resource utilization, and standardize delivery. Images provide a common artefact for developers, testers, release engineers, and operators. Layer caching can reduce repeated build work. The process model supports rapid replacement and horizontal scaling. Container orchestration platforms can schedule workloads, restart failed processes, provide service discovery, and perform rolling updates.
Containers also improve organizational collaboration. A developer can provide a reproducible development environment; a security team can scan the same image that operations deploys; and an audit team can trace a release to source, build metadata, and approvals.
Limitations and Risks
Containers add a management layer. Teams must understand image construction, registries, networking, storage, identity, secrets, vulnerability management, monitoring, and orchestration. A large number of small services can increase latency and operational burden.
The shared kernel means that container isolation is not equivalent to a separate physical machine or a fully independent VM. Vulnerable base images and outdated dependencies can introduce supply-chain risk. Images may accidentally contain passwords, private keys, proprietary code, or unnecessary utilities. Running as root, granting broad capabilities, mounting sensitive host paths, and exposing management sockets are common hazards.
Containers do not automatically solve data persistence, licensing, compliance, disaster recovery, or performance problems. They can also conceal inefficient applications: a badly designed service remains badly designed when packaged as an image. Finally, cloud usage may become more expensive if orchestration resources, data transfer, observability, and idle capacity are not governed.
Security, Governance, and Professional Responsibility
A secure container program applies controls throughout the software supply chain. Organisations should use trusted and minimal base images, patch them regularly, scan dependencies and images, verify provenance and signatures where supported, and maintain a software bill of materials (SBOM). Builds should run in controlled environments and should not receive unnecessary credentials.
At runtime, recommended controls include non-root users, read-only filesystems where practical, dropped Linux capabilities, restrictive seccomp or equivalent policies, network segmentation, resource limits, and explicit access to secrets. Secrets should be supplied through an appropriate secret-management system rather than embedded in Dockerfiles, image layers, source code, or command histories.
Governance should define who may publish images, how long images are retained, how vulnerabilities are prioritised, what evidence is required for release, and how incidents are reported. Regulatory obligations may involve personal data, financial records, health information, data residency, retention, and auditability. Containerization changes the implementation, not the organisation’s legal responsibility for the data it processes.
Ethically, teams should consider the effects of automation on employment, surveillance, service reliability, and access to digital services. Faster deployment is not beneficial if it increases outages or exposes personal information. Technical decisions should be evaluated against users’ safety, privacy, accessibility, and legitimate expectations.
A fictional retailer operates an online ordering system. The original application runs on a manually configured server. Developers test against different library versions, deployments require several hours, and a minor change to payments risks affecting the entire system.
Problem
The organisation needs more frequent releases and improved reliability during seasonal demand. It also needs evidence that production software corresponds to reviewed source code and approved dependencies.
Analysis
The team maps the system into capabilities: web interface, catalogue, order processing, payment integration, and notifications. It discovers that the database and payment provider contain important state and should not be placed casually inside disposable application containers. It also identifies shared configuration files and undocumented server changes as major sources of drift.
Approach and Solution
The team first creates automated tests and a Dockerfile for the existing application. The image uses a supported minimal base, creates a non-root user, copies only required files, and defines an explicit startup command. Dependencies are locked, and the build pipeline records the source revision. The resulting image is scanned and pushed to a private registry using a release-specific tag and digest.
Next, the team separates the catalogue and notification components where independent deployment provides clear value. Configuration is injected at deployment time, while credentials are supplied through a secret manager. Logs are emitted to standard output and collected centrally. Health checks distinguish whether a process is alive from whether it is ready to receive traffic. The database remains a managed service with backups and tested restoration procedures.
A gradual deployment sends a small proportion of traffic to the new release. Metrics include error rate, latency, resource consumption, order completion, and payment failures. An automated rollback is available if defined thresholds are exceeded.
Outcome
Release preparation becomes repeatable, environment differences are reduced, and services can be scaled independently during peak periods. The team also discovers that containerization alone did not solve database migration, observability, or incident-response requirements; these had to be designed explicitly.
Learning Points
The case demonstrates that successful container adoption is an organisational and engineering change, not merely a packaging exercise. The valuable outcomes arise from combining images with automated testing, secure supply-chain controls, declarative deployment, monitoring, and disciplined ownership.
Best Practices for Initial Adoption
Begin with a clearly understood application and measurable objectives.
Keep one primary application process per container where practical.
Use small, maintained base images and pin important dependencies.
Build images reproducibly and label them with source and build metadata.
Prefer immutable image promotion over rebuilding separately for each environment.
Never place secrets in images or source-controlled Dockerfiles.
Run as a non-root user and minimise privileges.
Externalise persistent data and design backup and recovery procedures.
Implement logs, metrics, traces, readiness checks, and resource limits.
Scan images continuously and establish a response process for vulnerabilities.
Document ownership, support boundaries, compliance requirements, and rollback methods.
Adopt orchestration only when the operational benefits justify its complexity.
Contemporary Developments
Container platforms increasingly integrate software-supply-chain attestations, SBOM generation, policy enforcement, confidential-computing options, and automated vulnerability remediation. WebAssembly is being explored for portable, fast-starting workloads with a different execution model from conventional Linux containers. Platform engineering teams are creating internal developer platforms that hide unnecessary infrastructure complexity while preserving governance.
Artificial intelligence workloads also use containers to package model servers, libraries, and accelerator dependencies. This introduces additional concerns, including GPU scheduling, large image sizes, model provenance, data privacy, and the cost and environmental impact of computation. AI does not change the foundational principles: the image must be trusted, dependencies controlled, access restricted, and behaviour monitored.
Chapter Summary
Containerization packages application code and its user-space dependencies into a portable runtime artefact. Unlike a virtual machine, a container normally shares the host kernel, which reduces overhead but creates compatibility and security considerations. Docker provides tools and objects—images, containers, Dockerfiles, registries, volumes, networks, and Compose—for building and operating containerized applications.
Portability is conditional rather than absolute; immutability supports controlled replacement; reproducibility reduces environmental drift; and ephemerality encourages externalized state and automated recovery. Containers support microservices and cloud-native practices, but they do not automatically produce good architecture. Their value depends on automation, observability, secure supply chains, governance, and appropriate data management.
In digital transformation, containers help organisations standardise delivery, shorten feedback cycles, scale services, and connect development with operations. Their limitations require professional judgement: shared-kernel security, persistence, complexity, compliance, cost, and operational capability must be addressed explicitly.
Key Terms
Containerization: Packaging an application with its user-space dependencies for isolated execution.
Virtual machine: A software-defined computer that normally includes a complete guest operating system.
Hypervisor: Software that creates and manages virtual machines.
Container runtime: Software that creates and runs containers.
Image: A versioned, usually read-only package used to create containers.
Container: A running instance of an image.
Layer: A filesystem change contributing to an image.
Dockerfile: A text file containing image-build instructions.
Registry: A service for storing and distributing images.
Tag: A human-readable image label that may be changed.
Digest: A content-derived identifier for an image manifest.
Portability: The ability to move software between compatible environments with limited modification.
Immutability: The practice of replacing versioned artefacts rather than modifying them in place.
Microservice: A relatively independent service aligned with a business capability.
Orchestration: Automated scheduling, networking, scaling, and lifecycle management of containers.
Volume: Managed persistent storage mounted into a container.
Namespace: An operating-system mechanism that provides an isolated view of resources.
Control group: A mechanism for accounting for and limiting process resources.
SBOM: A software bill of materials listing components and dependencies.
Cloud-native: An approach emphasising automation, elasticity, resilience, observability, and loose coupling.
Review Questions
Short Answer Questions
What is the principal architectural difference between a virtual machine and a container?
Why should tags not be treated as immutable image identifiers?
Define container immutability and explain its relationship to persistent data.
Name two operating-system mechanisms commonly associated with Linux container isolation.
Why does containerization not automatically create a microservice architecture?
Long Answer Questions
Compare virtual machines and containers in terms of isolation, portability, resource use, and appropriate applications.
Explain the Docker image-to-container lifecycle from source code through deployment.
Discuss the benefits and limitations of containers in a DevOps delivery pipeline.
Explain how cloud-native principles complement, but differ from, containerization.
Develop a security and governance policy for an organisation beginning to use private container registries.
Analytical / Application Questions
An organisation wants to place its database, application, and uploaded files in disposable containers. Analyse the risks and propose a more appropriate architecture.
A container image works on a developer’s laptop but fails in production. Identify at least five possible causes and describe a systematic investigation.
A retailer is deciding whether to split a monolith into ten microservices during container adoption. Evaluate the decision criteria and recommend a phased approach.
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 normally includes a guest operating system.
B. A container always provides stronger isolation than a virtual machine.
C. A virtual machine cannot run on cloud infrastructure.
D. A container must include a complete independent kernel.
Correct Answer: A. A container normally shares the host kernel, while a virtual machine normally includes a guest operating system.
Question 2
Which Docker object is used as the read-only package from which containers are created?
A. Volume
B. Image
C. Network
D. Registry credential
Correct Answer: B. Image
Question 3
Why is a container image digest generally more reliable than a tag for release identification?
A. A digest is content-derived, while a tag can be moved to another image.
B. A digest always makes an image smaller.
C. A tag contains encryption keys, while a digest does not.
D. A digest prevents all runtime vulnerabilities.
Correct Answer: A. A digest is content-derived, while a tag can be moved to another image.
Question 4
Which practice best supports container immutability?
A. Manually editing files inside a production container
B. Rebuilding and redeploying a tested image for a change
C. Disabling image versioning
D. Storing passwords in the Dockerfile
Correct Answer: B. Rebuilding and redeploying a tested image for a change
Question 5
What is the main purpose of a Docker registry?
A. To provide physical CPU hardware
B. To store and distribute container images
C. To replace application source control
D. To guarantee that applications are stateless
Correct Answer: B. To store and distribute container images
Question 6
Which statement about microservices is correct?
A. Every container is necessarily a microservice.
B. Microservices are independent capabilities, and containers are one possible packaging method.
C. Microservices cannot communicate over networks.
D. A monolith cannot be containerized.
Correct Answer: B. Microservices are independent capabilities, and containers are one possible packaging method.
Question 7
Which practice most directly reduces the risk of exposing credentials in container deployments?
A. Embedding credentials in the image layer
B. Passing credentials through a managed secret-management system
C. Using a public registry for all images
D. Running every process as root
Correct Answer: B. Passing credentials through a managed secret-management system
Question 8
What is the principal role of a volume?
A. To provide persistent storage that can outlive a container
B. To compile application source code
C. To act as a container image tag
D. To create a guest operating-system kernel
Correct Answer: A. To provide persistent storage that can outlive a container
Question 9
Which statement is a limitation of containerization?
A. Containers can never be automated.
B. Containers eliminate the need for monitoring.
C. Containers share a kernel and therefore require careful security and compatibility management.
D. Containers cannot be used in cloud environments.
Correct Answer: C. Containers share a kernel and therefore require careful security and compatibility management.
Question 10
A team wants to deploy exactly the same tested artefact to staging and production. Which approach best supports this objective?
A. Rebuild the image manually in each environment
B. Promote the tested image identified by a release digest
C. Install dependencies directly on each host
D. Modify the running production container before release
Correct Answer: B. Promote the tested image identified by a release digest