Appearance
Why Containers, and How They Differ from VMs
16. What problem does containerization solve?
The short answer
An application needs more than its own code to run. It needs a language runtime, libraries, system packages and settings, all at the right versions. Containerization packs the application together with everything it needs into one image, and runs it as an isolated process. The same image then runs the same way on a laptop, in CI and in production.
Start with the oldest complaint in software: "it works on my machine."
A developer writes a Node.js service on a laptop. The laptop has Node.js version 20 and a certain version of the OpenSSL library. The production server was set up two years ago. It has Node.js 18 and an older OpenSSL. The code is identical, but the surroundings are different, so the service crashes in production.
The code was never the whole program. A running program is its code plus everything around it. That includes:
- The language runtime, such as Node.js, Python or Java.
- Libraries, both the ones your code imports and the system ones they need.
- Operating system packages and tools, such as
curlor certificate files. - Configuration, such as file paths, environment variables and time zone.
Before containers, teams tried to keep every server's surroundings identical by hand, or with scripts. Over months, servers drifted apart. Somebody installed a patch on one server and not another. These hand-tuned, slightly different servers got a nickname: snowflake servers, because no two are alike.
Containerization flips the problem around. Instead of preparing the server to suit the app, you ship the app with its surroundings already attached.
That one idea solves several problems at once:
- Consistency. The image is built once. Every environment runs those exact bytes. "Works on my machine" becomes "works on every machine".
- No conflicts between apps. One app can use Python 3.9 and another Python 3.12 on the same server. Each brings its own copy, so they never collide.
- Density. Containers are light, so one server can run many of them. Question 19 explains why they are light.
- Speed. A container starts in well under a second, because it is just a process. Scaling up and replacing broken copies become fast.
- Simple releases and rollbacks. A release is "run the new image". A rollback is "run the previous image". Nothing is installed or uninstalled on the server.
The shipping container comparison. Before standard shipping containers, every cargo was loaded by hand in its own way: sacks, barrels, crates. After the standard steel box, a crane does not care what is inside. It lifts every box the same way. A software container does the same for servers. A server does not care whether the box holds Java, Python or Go. It runs every box the same way.
Why they ask: to check that you understand the root problem, which is shipping an app's surroundings along with it, rather than just knowing that "containers are lightweight".
17. What is Docker, and which problems does it solve for developers and operations teams?
The short answer
Docker is a set of tools that made containers easy to use. It gives you a standard way to build an image from a recipe called a Dockerfile, share that image through a registry, and run it with one command. Developers get identical, quick-to-start environments. Operations teams get one standard package format for every application, whatever language it is written in.
Containers existed long before Docker. Linux already had the building blocks. chroot, from 1979, could give a process its own view of the filesystem. Later came namespaces and cgroups, the kernel features that actually isolate a container (questions 99 and 100). LXC, in 2008, combined them. But using them was hard and every setup was different.
Docker arrived in 2013 and added three things that made containers practical:
- The image format. A container's files are packed into stacked layers that can be shared and cached. Question 26 explains layers.
- The Dockerfile. A short, readable recipe for building an image, kept in Git next to the code.
- The registry. A server you push images to and pull them from, like a library for images. Docker Hub was the first big public one.
Today "Docker" means a few different things, and it helps to name them precisely:
- Docker Engine, the background service that builds and runs containers on a Linux machine. Its open-source core is called Moby.
- The Docker CLI, the
dockercommand you type. - Docker Desktop, an app for Mac and Windows that runs a small Linux virtual machine so Docker works there too.
- Docker, the company, which also runs Docker Hub.
What it solves for developers:
- One command to get a working environment.
docker compose upstarts the app, its database and its cache, at the right versions. A new teammate is productive on day one instead of day three. - No more installing everything locally. You do not need PostgreSQL installed on your laptop. You run it in a container and delete it when you are done.
- The same environment as production. You test against the same image that will ship.
What it solves for operations teams:
- One standard package. Java, Python and Go apps all become images, and every image is deployed the same way.
- Isolation and limits. Each container gets its own view of the system, plus caps on memory and CPU.
- Fast, safe changes. Deploying is starting a new image. Rolling back is starting the old one.
A detail that shows depth: Kubernetes stopped using Docker Engine to run containers in version 1.24, released in 2022. Many people read that as "Kubernetes dropped Docker". It did not drop Docker images. Images built with Docker follow an open standard (question 461), so Kubernetes runs them with other runtimes such as containerd. Docker is still the most common way to build them.
18. What is the difference between a container and a virtual machine?
The short answer
A virtual machine pretends to be a whole computer, so it runs its own complete operating system with its own kernel. A container is just a normal process on the host, which the host's kernel walls off so it sees only its own files, network and processes. Virtual machines share the hardware. Containers share the kernel.
First, one word you need: the kernel. The kernel is the core of an operating system. It is the only program allowed to touch the hardware directly. Every other program asks the kernel for things, like "open this file" or "send this network packet". Those requests are called system calls.
Now the difference becomes simple.
A virtual machine (VM) runs on a hypervisor. A hypervisor is software that splits one physical computer into several pretend computers. Each pretend computer gets its own virtual CPU, memory and disk. Inside it, you install a complete operating system, kernel included. So ten VMs means ten kernels running at once.
A container has no kernel of its own. It is an ordinary process on the host. The host's kernel uses two features to give it a private world. Namespaces control what the process can see: only its own files, its own process list, its own network. Cgroups control how much it can use: a cap on memory and CPU. Ten containers means ten processes, all using the one host kernel.
A comparison you can say out loud: VMs are like separate houses. Each has its own foundation, plumbing and electricity. Containers are like flats in one apartment building. Each flat has its own front door and lock, but they share the foundation and the pipes. Flats are cheaper and quicker to set up. Houses are more separate from each other.
| Virtual machine | Container | |
|---|---|---|
| Has its own kernel | Yes | No, shares the host's |
| Typical image size | Gigabytes | Megabytes |
| Start time | Seconds to minutes | Under a second |
| Isolation boundary | Hypervisor | Kernel features |
| Can run a different OS | Yes, any OS | Same kernel type only |
The last row matters. Because a container uses the host's kernel, a Linux container needs a Linux kernel. That is why Docker Desktop on a Mac quietly runs a small Linux VM, and your containers run inside it.
19. Why can containers start faster and use fewer resources than virtual machines?
The short answer
Starting a container is starting a process. There is no kernel to boot and no operating system services to bring up, so it takes milliseconds. A container also only uses the memory its own process needs, while a VM reserves memory for a whole operating system. And containers built from the same image share the same files on disk and in memory.
Compare what actually happens at start-up.
Starting a VM is like turning on a real computer:
- The virtual firmware runs.
- A bootloader loads the guest kernel.
- The kernel starts, detects its virtual hardware and mounts disks.
- An init system (such as systemd) starts dozens of services: logging, networking, time sync, SSH.
- Only then does your application start.
That takes from several seconds to a few minutes.
Starting a container is much shorter:
- The runtime asks the kernel to create new namespaces and a cgroup.
- It points the process at the image's files as its root filesystem.
- It starts your application's process.
The kernel is already running, and it does steps 1 and 2 in milliseconds. In practice, a container's start time is almost entirely your application's own start time.
Why containers use less memory. A VM must hold a whole operating system in its memory: a kernel plus all those services, often a few hundred megabytes before your app starts. A container holds only your app's process. Ten small containers might use 500 MB in total. Ten small VMs might need 5 GB for the same apps.
Why containers use less disk. Images are made of layers, and layers are shared. If twenty images are built on the same Debian base layer, the machine stores that layer once. Question 26 explains layers.
A deeper point about shared memory. When two containers from the same image read the same library file, the kernel loads it into memory once. It keeps a single copy in its page cache, which is the memory where the kernel keeps recently read files, and both containers use that copy. VMs cannot share like this, because each VM has its own kernel and its own page cache.
An honest caveat. The CPU itself is not much faster in a container. Modern VMs use hardware support for virtualization, so ordinary calculations run at almost full speed in both. The big wins are start time, memory and disk. There are also very small VMs, called microVMs, such as Firecracker, used by AWS Lambda. They boot in around a tenth of a second by removing almost everything a normal VM boots. That narrows the start-up gap, while keeping a separate kernel.
20. What are the trade-offs between containers and virtual machines in isolation, security, portability, and operations?
The short answer
VMs isolate more strongly, because each has its own kernel and the hypervisor is a small, hard barrier. Containers share the host kernel, so a kernel bug can let a container escape, and they need careful hardening. Containers are more portable between Linux machines and much faster to operate, but they need an orchestrator to run at scale. Most clouds combine both: containers running inside VMs.
Take the four areas one at a time.
1. Isolation. How well one workload is kept away from another.
- A VM's wall is the hypervisor. It is a small piece of software with a narrow job, so there are few ways through it.
- A container's wall is the shared kernel, which is huge and exposes hundreds of system calls. Every system call is a possible door. Real escapes have happened through kernel bugs. One well-known example is "Dirty Pipe" (CVE-2022-0847), which let an ordinary process write to files it should only be able to read.
- Containers also share things cgroups cannot fully divide. A container that fills the kernel's file caches, or opens huge numbers of network connections, can slow its neighbours. This is called the noisy neighbour problem.
2. Security. What you must do to be safe.
- VMs are safer by default for running code you do not trust.
- Containers are safe enough for your own code when hardened: run as a non-root user, drop Linux capabilities, apply a seccomp filter, and use a read-only filesystem. Question 101 explains each of these.
- When you must run untrusted code in containers, use a sandboxed runtime. gVisor puts a fake kernel in between the container and the real one. Kata Containers runs each container in its own tiny VM. You keep the container workflow and get VM-like isolation.
3. Portability. How easily it moves between machines.
- A container image runs on any Linux machine with a compatible kernel and the same CPU type. An image built for Intel and AMD processors (
amd64) does not run on ARM processors (arm64) unless you build for both. Question 82 covers that. - A Linux container cannot run on a Windows or Mac kernel directly. It needs a Linux VM underneath, which Docker Desktop provides.
- A VM image can carry any operating system, but VM images are large and each hypervisor has its own format.
4. Operations. What running them day to day is like.
- Containers are quick to build, ship and replace. They are immutable: you never patch a running container, you replace it with a new image. That removes configuration drift.
- Containers are short-lived, so logs and data must be stored outside them. At scale you need an orchestrator such as Kubernetes to place, restart and connect them.
- VMs are long-lived, so they need their operating systems patched one by one, and they drift apart over time. In return, VM tooling is very mature: backups, snapshots, and moving a running VM to another host without stopping it.
| Virtual machines | Containers | |
|---|---|---|
| Isolation | Strong | Weaker, shared kernel |
| Untrusted code | Safe by default | Needs a sandbox runtime |
| Image size | Large | Small |
| Moving between hosts | Heavy | Easy on same kernel and CPU |
| Patching | Per machine | Rebuild and replace |
| At scale | Mature tools | Needs an orchestrator |
The answer that shows real experience: it is rarely one or the other. In every major cloud, your Kubernetes nodes are VMs, and your containers run inside them. The VM wall separates you from other customers. The containers give you speed and density inside your own space. You get the strengths of both.
461. What is the OCI, and why does it matter that images and runtimes follow its standards?
The short answer
The OCI, the Open Container Initiative, is the group that writes the open standards for containers. There are three: how an image is packed, how a container is run, and how a registry serves images. Because Docker, containerd, Podman, Kubernetes and every major registry follow them, an image built by one tool runs on all the others. Nobody is locked in to one vendor.
In 2015, containers were growing fast and there was a real risk that every company would invent its own incompatible format. Docker and other companies formed the Open Container Initiative under the Linux Foundation, a neutral non-profit. Docker donated its image format and its low-level runtime as the starting point.
The OCI publishes three specifications. A specification is a precise written description of how something must work.
- The image specification. It describes what an image is: a small JSON manifest that lists a config and a set of layers, each identified by a cryptographic hash. Question 21 explains each piece.
- The runtime specification. It describes how to run a container from an unpacked folder of files plus a
config.jsonthat says which program to start, which namespaces to create, and which limits to apply.runcis the reference program that does this. Question 32 shows where it fits. - The distribution specification. It describes the HTTP API a registry must offer, so any client can push and pull from any registry.
Why it matters in practice:
- You can mix tools freely. Build an image with Docker on your laptop. Push it to Azure Container Registry, Amazon ECR or a private Harbor server. Run it in Kubernetes with containerd or CRI-O. Every step works, because every tool speaks the same formats.
- This is why Kubernetes could stop using Docker Engine without breaking anyone's images (question 17).
- Registries store more than images now. The same format carries Helm charts, image signatures and software bills of materials. These are called OCI artifacts. Question 146 covers signatures and bills of materials.
Why they ask: it separates people who have only typed docker run from people who understand that "Docker image" really means "OCI image", and that the whole ecosystem rests on these shared standards.
462. What is the difference between Docker and Podman?
The short answer
Both build and run the same OCI containers with almost the same commands. The big difference is design. Docker sends every command to one long-running background service, the Docker daemon, which usually runs as root. Podman has no daemon: each container is started directly by the podman command, and it runs rootless by default. Podman also understands pods, groups of containers that share a network, like in Kubernetes.
Docker uses a client and a server. When you type docker run, the docker command does not start the container itself. It sends a request to dockerd, a background service, which does the work. That service usually runs as root, so anyone who can talk to it can effectively control the whole machine. Question 140 explains why that is dangerous.
Podman, made by Red Hat, has no central daemon. When you type podman run, Podman sets up the container itself and then hands it to a small helper process called conmon, which watches it. There is no always-running root service to attack.
The main differences:
| Docker | Podman | |
|---|---|---|
| Background daemon | Yes, dockerd | None |
| Rootless by default | No, optional | Yes |
| Pods | No | Yes, like Kubernetes |
| Commands | docker ... | Same words, podman ... |
| Multi-container tool | Docker Compose | podman compose, Quadlet |
The commands really are almost the same. Many people simply set alias docker=podman and keep working. Images are identical, because both follow the OCI standards.
Pods are a nice extra. In Podman you can group containers into a pod that shares one network, so they reach each other on localhost, exactly as in a Kubernetes pod. Podman can even write out a Kubernetes manifest from a running pod with podman kube generate, and run a Kubernetes manifest locally with podman kube play.
Running as a system service. Without a daemon, something else must restart containers when the machine reboots. Podman hands this job to systemd, the standard Linux service manager. A feature called Quadlet lets you describe a container in a small file and systemd starts and supervises it.
When teams choose which:
- Podman on Red Hat-family servers, on shared machines where no root daemon is allowed, and in CI systems that build images without root.
- Docker for its huge developer ecosystem: Docker Desktop, Compose, and BuildKit's advanced build features.
Why they ask: it checks whether you know that the daemon is a design choice with security costs, not something containers require.