Virtualization is a layer between physical hardware and the application that allows software to be decoupled from specific hardware.
It enables:
A virtualization layer (hypervisor) separates guest operating systems from the physical hardware.
+------------------+
| Guest OS + App |
+------------------+
| Hypervisor |
+------------------+
| Hardware |
+------------------+
+------------------+
| VM: Guest OS+App |
+------------------+
| Hypervisor |
+------------------+
| Hardware |
+------------------+
Examples: VMware ESXi, Xen, Hyper-V, KVM (in Linux), Proxmox
+------------------+
| Guest OS + App |
+------------------+
| Hosted hypervisor|
+------------------+
| Host OS |
+------------------+
| Hardware |
+------------------+
Examples: VirtualBox, VMware Workstation/Fusion, Parallels
A virtual machine creates a completely separate environment:
Virtual machines are:
Containers emerged as a lighter alternative to VMs.
A container:
A container is not a virtual machine.
Docker is a platform for:
It uses OS-level virtualization.
+------------------+
| App (container) |
+------------------+
| Container runtime|
| (namespaces,cg.) |
+------------------+
| Linux kernel |
+------------------+
| Hardware |
+------------------+
+----------+
| registry | Docker Hub
+----------+
|| (image)
+----------+
| daemon | Host machine
+----------+
|| (protocol)
+------------+
| cli client | Host or manager machine
+------------+
The docker command in the command line.
docker run --rm -p 8080:80 nginx
--rm).A Dockerfile defines how an image is built.
Example:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
CMD ["nginx", "-g", "daemon off;"]
An image is composed of layers:
RUN, COPY, ADD typically create filesystem layers (cached, immutable).CMD/ENTRYPOINT set image metadata (do not add a filesystem layer).Base image
+------------------+
| ubuntu:22.04 |
+------------------+
RUN ... (adds a layer)
+------------------+
| + nginx files |
+------------------+
CMD ... (metadata)
Containers are ephemeral: the writable layer is disposable and can be recreated at any time.
Application state (data) must be stored outside the container:
Examples:
# bind mount (host path → container path)
docker run --rm --mount type=bind,src=/srv/site,dst=/usr/share/nginx/html,ro -p 8080:80 nginx
# named volume (managed by Docker)
docker run --rm --mount type=volume,src=site-cache,dst=/cache busybox true
Port mapping:
docker run -p 8080:80 nginx
Types of networks:
| VM | Docker (containers) |
|---|---|
| own OS/kernel | shared kernel |
| slow start | fast start |
| higher overhead | lower overhead |
Next step: