DevOps Engineering Containers04 / 21

SECTION 03 · 35 MIN READ & EXPLORE

Containers and Images

Explore isolated runtimes, disposable filesystems, background services, and port mappings.

What are Linux Containers?

A container runs a process using an image and a writable layer. Stopping, removing, and recreating it are different operations.

Under the hood, Linux containers are regular Linux processes isolated from each other by two kernel features while sharing the same host kernel: namespaces (what a process can see) and control groups / cgroups (how much CPU, memory, and I/O it can use).

EXPLORE THE DIAGRAM

Linux namespaces and cgroups

Experiment freely. Changes disappear when you reset or refresh.

Preview of Linux namespaces and cgroups

What are Container Images?

A container image is a self-contained, immutable package holding an application, its libraries, runtime, and base filesystem stacked as read-only layers. When you start a container from an image, Docker mounts those shared read-only layers and adds a thin read-write (R/W) layer on top for runtime changes.

EXPLORE THE DIAGRAM

Container images, layers, and the writable container layer

Experiment freely. Changes disappear when you reset or refresh.

Preview of Container images, layers, and the writable container layer

History of Containers

Containers did not start with Docker. They are the result of decades of Unix and Linux kernel work aimed at isolating processes without the overhead of running a separate operating system.

TIMELINE

From chroot to modern containers

  1. Filesystem

    chroot (Unix V7)

    Introduced the ability to change a process’s apparent root directory (/), creating the first building block for filesystem isolation.

  2. OS Isolation

    FreeBSD Jails

    Extended chroot by isolating processes, filesystems, users, and IP addresses into lightweight, self-contained environments.

  3. Kernel

    Linux Namespaces

    Starting with mount namespaces in Linux 2.4.19, the kernel progressively added PID, network, IPC, UTS, and user namespaces so processes see isolated views of the system.

  4. Resources

    Control Groups (cgroups)

    Added to the Linux kernel to limit, account for, and isolate resource usage such as CPU, memory, and disk I/O across groups of processes.

  5. Runtime

    LXC (Linux Containers)

    Combined namespaces and cgroups into the first complete Linux container implementation without requiring kernel patches.

  6. Culture & Practice

    DevOps

    Coined with the first DevOpsDays in Ghent, driving teams toward automated, repeatable, and fast software delivery—creating huge demand for consistent environments from laptop to production.

  7. Developer Tooling

    Docker

    Packaged Linux containers with portable layered images, a simple CLI, and a central registry—making containers practical for everyday development and deployment.

  8. Orchestration

    Kubernetes

    Open-sourced by Google to automate scheduling, scaling, self-healing, and networking of containerized applications across clusters of machines.

  9. Standard

    Open Container Initiative (OCI)

    Established open specifications for container image formats and runtimes (runc), enabling interoperability across Docker, Podman, containerd, and Kubernetes.

Why and When to Use Containers?

Work through these five scenarios to see when containers shine: isolating legacy runtimes, running disposable sandboxes, launching background services, serving local files, and executing one-off CLI tools.

READ

Killercoda — Interactive Linux & Docker Playgrounds (opens in a new tab)

Practice Docker commands and container scenarios directly in your browser using disposable Linux environments—no local setup required.

SCENARIOS

Running containers with docker run

Legacy Runtime (Python 2.7)

-it--rm
SITUATION

A legacy scoreboard service written in 2010 requires Python 2.7, while your workstation runs Python 3 and installing Python 2 locally would pollute your system.

TASK

Start an interactive Python 2.7 shell inside a disposable container and verify the interpreter version.

# 1. Check your host Python version (typically 3.x)
python --version

# 2. Start an interactive Python 2.7 container that cleans itself up on exit
docker run -it --rm python:2.7-alpine

# 3. Verify the version inside the container, then press Ctrl+D to exit
python --version

WHAT TO OBSERVE

Inside the container, python --version reports Python 2.7.x. Exiting destroys the container automatically (--rm), leaving your host environment untouched.

Ephemeral Sandbox (Alpine Linux)

-it--rm
SITUATION

You want to test destructive shell commands safely without risking files on your host machine.

TASK

Launch a minimal Alpine Linux container, break its filesystem, then start a fresh container from the same image.

# 1. Start a lightweight Alpine Linux shell
docker run -it --rm alpine sh

# 2. Delete /bin inside the container's writable layer
rm -rf /bin

# 3. Try running ls (fails because /bin/ls was removed)
ls

# 4. Exit and start a new container from the same image
exit
docker run -it --rm alpine sh
ls

WHAT TO OBSERVE

ls fails inside the first container after rm -rf /bin, but works immediately in the new container. Images are immutable; changes only live in a container’s disposable writable layer.

Background Service (Redis)

-d--name-p
SITUATION

Ticket scanners need a Redis instance for development, and you want to run it without installing Redis directly on your machine.

TASK

Start Redis in detached mode, publish port 6379 on localhost, verify connectivity with a temporary client container, and remove it.

# 1. Start Redis in the background with a name and localhost port mapping
docker run -d --name ticket-db -p 127.0.0.1:6379:6379 redis

# 2. Confirm the container is running
docker ps

# 3. Connect from a temporary container sharing the same network namespace
docker run -it --rm --network container:ticket-db redis redis-cli -h 127.0.0.1

# 4. Inside redis-cli, run PING (expect PONG), exit, and clean up
docker rm -f ticket-db

WHAT TO OBSERVE

docker ps lists ticket-db as Up, and redis-cli returns PONG when you send PING.

Serving Local Files (Nginx Bind Mount)

-d--name-p-v
SITUATION

You have a local HTML page on your workstation and want to serve it through Nginx with live updates as you edit.

TASK

Mount your current working directory into an Nginx container and verify live edits in the browser.

# 1. Create a local HTML file
echo "<h1>Match Day: Morocco vs. Brazil</h1>" > index.html

# 2. Run Nginx and bind-mount the current directory to Nginx's web root
docker run -d --name press-server -p 127.0.0.1:8080:80 -v "$(pwd)":/usr/share/nginx/html nginx

# 3. Open http://localhost:8080 in your browser

# 4. Edit the file locally and refresh the browser to see the update
echo "<h1>Full Time: 1-0</h1>" > index.html

# 5. Clean up when finished
docker rm -f press-server

WHAT TO OBSERVE

Opening http://localhost:8080 renders your local index.html, and refreshing after editing the host file immediately displays the updated content without restarting the container.

One-Off CLI Task (Whalesay)

--rm
SITUATION

You need to run a single command-line utility without installing it or its dependencies on your workstation.

TASK

Run a containerized CLI tool with custom arguments and let it exit and remove itself automatically.

# Pass command arguments to the container and remove it as soon as it exits
docker run --rm docker/whalesay cowsay "Kickoff at 20:00!"

WHAT TO OBSERVE

The container prints the ASCII art message to stdout, exits immediately, and disappears from docker ps -a.

Quick Reference

CHEAT SHEET

Docker CLI & flags to remember

Core CRUD operations for images and containers, plus the most common docker run flags.

Images (CRUD)

docker build
Build an image from a Dockerfile
CREATE
docker image ls
List local images (alias: docker images)
READ
docker build / tag
Rebuild or retag an image
UPDATE
docker rmi
Delete an image
DELETE

Containers (CRUD)

docker run
Create and start a container
CREATE
docker ps -a
List running (or all) containers
READ
docker exec
Run a command inside a running container
UPDATE
docker rm
Remove a container (-f to force)
DELETE

Common docker run flags

-it
Interactive terminal attached to the container
--rm
Automatically remove the container when it exits
-d
Detached mode (run container in the background)
--name NAME
Assign a custom, readable container name
-p HOST:CONT
Publish a container port to the host
-v SRC:DEST
Mount a host directory or named volume
EXPLORE THE DIAGRAM

Containers: the course whiteboard

Experiment freely. Changes disappear when you reset or refresh.

A LITTLE CLEARER?

Take a moment to explain the idea in your own words.

Progress is saved in this browser.

DevOps Engineering

Course overview ↗

01Introduction to DevOps

  1. What is DevOps?20m
  2. DevOps Roles20m