Servers, VMs, and Containers

Expected level: Awareness

A server is a computer or program that answers requests. Virtual machines and containers are two ways to run many isolated workloads on shared hardware, so one physical machine can host many applications.

Three levels of isolation

  • A physical server (bare metal) is one machine with one operating system shared by everything on it. It is simple and fast, but hard to share safely and slow to replace.
  • A virtual machine (VM) is made by software called a hypervisor, which divides one physical machine into several virtual ones. Each VM has its own full guest operating system, virtual disks and network. Isolation is strong, but each VM is heavy: gigabytes of disk and minutes to boot.
  • A container is an isolated process (or group of processes) that shares the host’s operating system kernel but has its own filesystem, libraries and network view. It starts in seconds and is small, because it carries only the application and its dependencies.

VM versus container

VM Container
Includes Full guest operating system App and its dependencies only
Kernel Its own Shared with the host
Size and startup Large, slower Small, fast
Isolation Stronger (hardware level) Lighter (operating system level)
Typical use Running different operating systems, strong separation Packaging and running one service consistently

Choose a VM when you need a different operating system, strong isolation between workloads (for example untrusted tenants) or when running a legacy application that expects a whole machine. Choose a container for consistent packaging, fast start and many small services on one host. Both help with “it works on my machine”, because the environment is defined and repeatable instead of depending on one person’s setup.

A container shares the host kernel, which is why Linux containers need a Linux kernel. On Windows, tools such as Docker Desktop run them through WSL or a small VM.

Why they exist

Containers address “it works on my machine”. The same image, holding the app and what it needs, runs on a laptop, in test and in production (see Environments), and many containers share one host efficiently.

  • An image is the read-only template, and a container is a running instance of it. A Dockerfile is the recipe for building an image.
  • Orchestration tools such as Kubernetes start, scale and restart many containers across machines.
  • “Server” can also mean software: a web server is a program that can run on any machine.

VMs and containers are usually rented from a cloud provider and not owned.

Try it

If you have Docker or a similar tool, run docker run --rm hello-world, then write two sentences on what was started and how that differs from starting a VM. Without the tool, read the Docker page above and explain the difference between a VM and a container in your own words.

Common mistakes

  • Assuming a container is as isolated as a VM.
  • Mixing up an image with a running container.
  • Forgetting that Linux containers need a Linux kernel, even on Windows.

Check yourself

  • What do a VM and a container each include?
  • When would you choose a VM over a container?
  • How do containers help with "works on my machine"?

Related topics

Terms

Further reading