Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 5.6: OS-level virtualization: containers, Docker basics, containers vs virtual machines

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.

Module 5 1 hour Theory CO5
← Before
5.5 Virtual machines
Hypervisors
You are here
5.6 OS-level virtualization: containers, Docker basics, containers vs virtual machines
Module 5 · Managing Devices, Security, Protection and Virtualization
Next →
6.1 Contemporary issues
Module 6

Learning objectives

By the end of this session you should be able to:

  • Explain OS-level virtualization and how it differs from hardware virtualization.
  • Describe namespaces, cgroups and union file systems.
  • Use basic Docker commands and write a simple Dockerfile.
  • Compare containers and virtual machines on kernel, size, start-up time and isolation.

Lecture notes

1. OS-level virtualization

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

App A | App B
bins/libs | bins/libs
guest OS | guest OS
hypervisor
host hardware

Containers

App A | App B
bins/libs | bins/libs
container engine (Docker)
host OS kernel (shared)
host hardware

2. The kernel features behind containers

Namespaces — what a container can see

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).

cgroups — what a container can use

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).

Union file system — what it is made of

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).

3. Docker basics

Image

A read-only template: files + metadata (e.g. ubuntu:22.04, gcc:13).

Container

A running (or stopped) instance of an image — a set of processes in namespaces and cgroups.

Dockerfile

A text recipe that builds an image layer by layer.

Registry

A store of images, e.g. Docker Hub; pull downloads, push uploads.

Terminal — the everyday Docker commands
$ 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 CPU
Dockerfile — packaging a lab program (e.g. Lab 5's scheduler)
FROM 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
Terminal
$ docker build -t sched .         # build an image named sched
$ docker run -it sched            # run it: same result on any machine with Docker

docker 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.

4. Containers vs virtual machines

Virtual machineContainer
What is virtualisedThe hardwareThe operating system (user space)
KernelEach VM runs its own guest kernelAll containers share the host kernel
Guest OS choiceAny (Windows on a Linux host)Same kernel family as the host (Linux containers need a Linux kernel)
SizeGigabytesMegabytes
Start-up timeSeconds to minutes (boot an OS)Milliseconds to seconds
DensityTens per hostHundreds to thousands per host
IsolationStrong — separate kernels, hardware-enforcedWeaker — a kernel bug can affect every container
Typical useMulti-tenant clouds, different OSes, strong security boundariesMicroservices, CI/CD, reproducible environments
They are often combined

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.

VideoBytes

Containers and Docker basics

Video coming soon

Containers and Docker basics

Recorded by Dr. Krithika L.B. Slot m5-containers

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
Can a Windows container run on a Linux kernel?

No — containers share the host kernel, so they must use the host's kernel type. A VM would be needed.

Which Linux feature limits a container's memory?

Control groups (cgroups).

Why does ps inside a container show the shell as PID 1?

The container has its own PID namespace; its first process is PID 1 inside it.

Give one reason to prefer a VM over a container.

Stronger isolation (separate kernels) for untrusted tenants, or the need to run a different OS.

What is the difference between an image and a container?

An image is a read-only template; a container is a running (or stopped) instance of an image with a writable layer.

Key takeaways

  • Containers share the host kernel; isolation comes from namespaces (view) and cgroups (limits).
  • Docker: images (layered, read-only), containers (instances), Dockerfiles (recipes), registries (distribution).
  • VMs: own kernel, strong isolation, heavy. Containers: shared kernel, light, fast — often run together.

Where this leads

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 →