AWS in 1 Min · Episode 82

Containers vs virtual machines on AWS

Two ways to package an app. Watch the one-minute video, then read the details.

David Gomez1:25 video · 3 min read

"Containers are just small virtual machines." It's a common shortcut, and it's wrong in a way that matters. Both package an application so it runs the same way everywhere, but they do it at different layers. That difference decides how fast things start, how much you can pack onto a server, and how strongly workloads are kept apart.

A virtual machine fakes a whole computer

A virtual machine (VM) is a software copy of an entire computer. A hypervisor sits on the physical hardware and splits it into several VMs. Each VM boots its own operating system (the guest OS), with its own kernel, and your app runs on top.

  • You get full control of the OS: kernel settings, drivers, system services.
  • Each VM carries a whole OS, so images are large and boot times are measured in tens of seconds or minutes, not milliseconds.
  • An EC2 instance is a VM. Current instance types run on the AWS Nitro hypervisor.

A container shares the host's kernel

A container packages just your app and its libraries. It does not boot an operating system. Every container on a host shares the host's OS kernel; the kernel keeps them apart with features such as namespaces and control groups, so each one sees only its own files, processes and resources.

  • Images are much smaller, because there's no OS inside, only what the app needs.
  • Containers typically start in seconds or less, so scaling out is quick.
  • You can run many more containers than VMs on the same machine.

The image is built once from a Dockerfile and runs the same on a laptop, in CI and in production.

The trade-off: isolation

Sharing a kernel is what makes containers light, and it's also their weak spot. A VM has its own kernel behind a hypervisor, which is a stronger isolation boundary. Containers on one host share a kernel, so a serious kernel flaw can affect all of them.

That's why multi-tenant platforms often wrap containers in VMs. AWS Fargate, for example, gives each task its own isolation boundary: tasks don't share a kernel, CPU, memory or network interface with other tasks.

On AWS, you use both

It's not either-or. On AWS, containers almost always run on VMs:

  • Amazon ECS or Amazon EKS schedule your containers onto EC2 instances you choose and pay for.
  • AWS Fargate runs the same containers with no servers for you to manage; you pay for the CPU and memory each task asks for.
  • AWS Lambda can also run functions packaged as container images.

When to choose a VM: you need full control of the OS, special drivers, or older software that expects a whole machine. When to choose containers: you ship services often and want the same artifact everywhere, with fast scaling. A common mistake is putting a whole VM's worth of services into one giant container; one process per container keeps images small and failures contained.

Where AI fits

AI models ship as containers too. AWS Deep Learning Containers are prebuilt images, free to use, that bundle frameworks and serving engines such as PyTorch and vLLM, and they run on EC2, EKS and SageMaker. Amazon SageMaker AI always runs training scripts and deployed models in Docker containers. So even if you never write a Dockerfile, your models already live in one, and container skills carry straight over to model deployment.

Quick recap

  • A VM fakes a whole computer and boots its own OS on a hypervisor.
  • A container packages just the app and shares the host's kernel: smaller and faster, with weaker isolation.
  • On AWS, containers usually run on VMs (ECS or EKS on EC2), or on Fargate with no servers to manage.
AWS in 1 Min #82 · 1:25

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS