Containers and Docker basics
Containers and Docker basics
Recorded by Dr. Krithika L.B. Slot m5-containers
Isolating applications on one shared kernel with namespaces, cgroups and layered images; the core Docker workflow; and when to choose a container or a VM.
By the end of this session you should be able to:
In OS-level virtualization, a single OS kernel is shared, but applications run in isolated user-space instances called containers (also zones, jails). Each container sees its own file system, process tree, network interfaces and users, yet all use the host kernel. There is no guest kernel to boot, so containers start in milliseconds and use far less memory than VMs.
Virtual machines
Containers
Each namespace gives a private view of one resource: PID (its own process tree; its first process is PID 1), mount (file system), network (interfaces, ports), UTS (host name), IPC, user (root inside ≠ root outside).
Control groups limit and account for CPU share, memory, disk I/O and number of processes — a container cannot starve the host (Module 2 scheduling and Module 4 memory, applied per group).
An image is a stack of read-only layers (base OS files, libraries, your app). A running container adds a thin writable layer on top (copy-on-write, like Session 4.5).
A read-only template: files + metadata (e.g. ubuntu:22.04, gcc:13).
A running (or stopped) instance of an image — a set of processes in namespaces and cgroups.
A text recipe that builds an image layer by layer.
A store of images, e.g. Docker Hub; pull downloads, push uploads.
$ docker pull ubuntu:22.04 # download an image
$ docker images # list local images
$ docker run -it --name os1 ubuntu:22.04 bash # start a container with a shell
root@3f2a9c1b:/# ps -e # inside: its own PID namespace
PID TTY TIME CMD
1 pts/0 00:00:00 bash
9 pts/0 00:00:00 ps
root@3f2a9c1b:/# exit
$ docker ps -a # list containers (running and stopped)
$ docker start os1 && docker exec -it os1 bash # re-enter it
$ docker stop os1 && docker rm os1 # stop and delete
$ docker run -d --memory=256m --cpus=0.5 nginx # cgroup limits: 256 MB RAM, half a CPUFROM gcc:13 # base image with the compiler
WORKDIR /app
COPY sched_np.c .
RUN gcc sched_np.c -o sched_np # build at image-creation time
CMD ["./sched_np"] # what runs when the container starts$ docker build -t sched . # build an image named sched
$ docker run -it sched # run it: same result on any machine with Dockerdocker build executes each Dockerfile instruction and stores the result as a layer; unchanged layers are cached.
docker run asks the kernel to create namespaces and a cgroup, mounts the image layers plus a writable layer, and starts the CMD process — which is PID 1 inside the container.
The process sees only the container's files, processes and network; cgroups cap its CPU and memory.
docker push the image to a registry; anyone can pull and run the identical environment — “it works on my machine” solved.
At scale, Kubernetes schedules thousands of containers across a cluster, restarts failed ones and scales them with load.
| Virtual machine | Container | |
|---|---|---|
| What is virtualised | The hardware | The operating system (user space) |
| Kernel | Each VM runs its own guest kernel | All containers share the host kernel |
| Guest OS choice | Any (Windows on a Linux host) | Same kernel family as the host (Linux containers need a Linux kernel) |
| Size | Gigabytes | Megabytes |
| Start-up time | Seconds to minutes (boot an OS) | Milliseconds to seconds |
| Density | Tens per host | Hundreds to thousands per host |
| Isolation | Strong — separate kernels, hardware-enforced | Weaker — a kernel bug can affect every container |
| Typical use | Multi-tenant clouds, different OSes, strong security boundaries | Microservices, CI/CD, reproducible environments |
In the cloud, containers usually run inside VMs: the VM gives strong isolation between customers, the containers give fast, dense deployment of each customer's applications. Lightweight VMs such as AWS Firecracker blur the line further.
Containers and Docker basics
Recorded by Dr. Krithika L.B. Slot m5-containers
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0No — containers share the host kernel, so they must use the host's kernel type. A VM would be needed.
Control groups (cgroups).
The container has its own PID namespace; its first process is PID 1 inside it.
Stronger isolation (separate kernels) for untrusted tenants, or the need to run a different OS.
An image is a read-only template; a container is a running (or stopped) instance of an image with a writable layer.
You now have the complete syllabus toolkit — processes, synchronization, memory, files, devices, protection and virtualization. Module 6 looks at where operating systems are heading.
Go to Module 6 — Contemporary issues →