Containers and virtual machines
🏠The everyday picture
Shipping containers changed world trade: every container is the same size, so any ship, train or truck can carry it, and what's inside doesn't matter to the crane. Software containers do the same for apps.
📘What it really is
-
A container packages an app with everything it needs to run (the runtime, libraries, settings) into one unit that runs the same on your laptop, a test server and production. "It works on my machine" stops being a problem.
-
Containers vs virtual machines (Module 63, Lesson 5):
- a VM includes a whole operating system and kernel; it's heavy (gigabytes, minutes to start);
-
a container shares the host's Linux kernel and isolates only the app; it's light (megabytes, seconds to start).
-
Many containers can run on one server, each isolated from the others.
-
Docker is the most popular tool for building and running containers. Images follow an open standard (OCI), so they also run on Podman, Kubernetes and cloud container services (Module 68).
-
Key words:
- image: the packaged app, a read-only template;
- container: a running instance of an image;
- registry: where images are stored and shared (Docker Hub, GitHub Container Registry, cloud registries).
🖱️Try it
Install Docker. Run docker run hello-world, then docker run -it --rm ubuntu:24.04 bash, look around inside
(cat /etc/os-release), and exit. Run docker ps -a and docker images to see what was created.
✅Quick check
Why do containers start much faster than VMs?
Show the answer
They share the host's kernel and don't boot a whole operating system.
What's the difference between an image and a container?
Show the answer
An image is the packaged template; a container is a running instance of it.
