Cloud Fundamentals

What Containers Are and How They Differ From Virtual Machines

A plain explanation of software containers, how they compare with virtual machines in size, speed and isolation, and when each is a sensible choice.

On this page
  1. The problem containers solve
  2. What a container is
  3. A quick recap of virtual machines
  4. The key difference
  5. How they compare in practice
  6. Why people use containers
  7. Things to keep in mind
  8. Choosing between them

The problem containers solve

Software rarely runs on its own. It depends on a particular version of a language, a set of libraries and certain settings. A program that works on a developer’s laptop can fail on a server because one of those pieces is slightly different. This is the old complaint of “it works on my machine”.

A container solves this by bundling an application together with everything it needs to run, so it behaves the same wherever the container is started: on a laptop, on a test server or in the cloud.

What a container is

A container is a packaged, isolated environment for running an application. It contains the application, its libraries and its settings, but it does not include a full operating system of its own. Instead, containers on the same machine share the operating system’s core (the kernel) of the host computer, while the host keeps each container’s processes, files and network access separated from the others.

Two terms are worth knowing:

  • Image. A read-only template that describes what is inside: the application and its dependencies. Think of it as a recipe or a frozen snapshot of the environment.
  • Container. A running instance created from an image. You can start many containers from the same image.

Images are typically stored in a shared library called a registry, so teams can pull the same image into different environments.

A quick recap of virtual machines

A virtual machine (VM) imitates an entire computer in software. A layer called a hypervisor divides a physical machine into several VMs, and each VM runs its own complete operating system, with its own kernel, on top of virtual hardware. This is the same idea as virtual machines in general. VMs are also the building blocks behind much of the infrastructure rented from cloud providers.

The key difference

The difference is what each one virtualizes.

  • A VM virtualizes the hardware. Each VM carries a full operating system.
  • A container virtualizes the operating system. Containers share the host’s kernel and carry only the application and its needs.

An analogy: VMs are like separate houses, each with its own foundations, plumbing and wiring. Containers are like apartments in one building, sharing the foundations and main utilities but with their own locked doors and interiors.

How they compare in practice

Container Virtual machine
Includes its own OS No, shares the host kernel Yes, a full guest OS
Typical size Usually smaller Usually larger
Start-up time Often seconds or less Often longer, as an OS must boot
Density on one host Often more instances Often fewer instances
Isolation Good, but weaker boundary Stronger boundary
OS flexibility Same kernel family as the host Different operating systems can coexist
Typical use Packaging and scaling applications Running whole systems and mixed OSes

The word “typically” matters here: the figures depend heavily on the software and the setup, and these are tendencies rather than guarantees.

Isolation and security

Because VMs have separate kernels, the boundary between them is generally considered stronger. Containers share a kernel, so a serious flaw in that kernel, or a badly configured container, could affect others. This does not make containers unsafe, but it is a reason for care, such as giving containers only the permissions they need, applying the idea of least privilege, and keeping images updated. Container images contain third-party components, so they should be checked as part of routine vulnerability scanning.

Containers and VMs are also sometimes combined: containers running inside VMs gets some of the convenience of one and the stronger boundary of the other.

Why people use containers

  • Consistency. The same image runs in development, testing and production.
  • Efficiency. Because they skip the extra operating system, containers use fewer resources and start quickly, which suits workloads that scale up and down.
  • Fast delivery. Building an image fits naturally into continuous delivery, where each change is packaged, tested and released automatically.
  • Clean organization. Large applications are often split into small services, each in its own container. This is a common design but it does add complexity of its own.
  • Portability. Images can run on different hosts and providers that support the same container format, although the surrounding services can still tie you down, as discussed in vendor lock-in.

Things to keep in mind

Containers are usually disposable. A container can be stopped and replaced at any time, so data that must survive belongs in separate storage rather than inside the container. Understanding the different types of cloud storage helps with that.

Managing many containers takes tooling. Running a handful by hand is manageable. At larger scale, organizations use orchestration software that starts, stops, scales and replaces containers automatically. It is powerful but demands skills and care, and it is not needed for every project.

Images need maintenance. An image is a snapshot; it does not update itself. Old images can contain outdated software with known weaknesses, so rebuilding them regularly matters.

Not everything suits containers. Software that needs a different operating system, deep access to hardware or a particular legacy setup may be a better fit for a VM.

Cost still needs watching. Containers are cheap to start, so they can multiply unnoticed, adding to cloud costs.

Choosing between them

Rough guidelines:

  • Choose containers for applications built to be packaged, moved and scaled, especially when you want quick, repeatable releases.
  • Choose virtual machines when you need a whole operating system, stronger separation between workloads, or to run older software with little change.
  • Use both when it makes sense, for example containers running on a group of VMs.

Neither is better in every case. Start from the workload and the team’s skills, and choose the simplest option that does the job.

The complete guide to cloud fundamentals

Cloud Computing Explained Without the Jargon
Read the guide

Keep exploring

Guides from other topics

All topics →