Comparing Virtual Machines, Containers and Functions
This lesson explains Azure's three main compute types, virtual machines, containers and functions, and how to choose between them. It is the foundation for the rest of the compute module.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how virtual machines, containers and functions work.
- Compare the compute types by control, management effort, start-up time and billing.
- Identify the appropriate compute type for a workload.
Virtual machines
A virtual machine (VM) is a software emulation of a physical computer. A hypervisor on a physical host divides the host's CPUs, memory and storage among several VMs, and each VM runs its own complete operating system, such as Windows Server or a Linux distribution. Because the VM is a full computer, the customer can install any software and change any setting, which is why VMs are the IaaS compute option.
That flexibility has costs. Each VM carries the overhead of a full operating system, takes minutes to start, and needs the customer to patch, secure and maintain the operating system. VMs suit workloads that need full control, lift-and-shift migrations and software that cannot run in the other compute types.
Containers
A container packages an application with its libraries, configuration and dependencies into a single image. Whereas a VM virtualizes the hardware, a container virtualizes the operating system: containers on the same host share the host's operating system kernel and run as isolated processes. As a result, containers are lightweight, start in seconds and use fewer resources than VMs, so many containers can run on one host.
Containers are portable: an image built on a developer's laptop runs the same way in test and production, on-premises or in any cloud. They suit microservices, in which an application is split into small independent services, and applications that need to be deployed frequently and consistently. Docker is the most widely used container platform, and Kubernetes is the most widely used system for orchestrating many containers.
Why containers?
Functions
Azure Functions runs small pieces of code in response to events, without any server or container for the customer to manage. Functions start when a trigger fires, scale automatically with the number of events and, on consumption-based plans, cost nothing when idle because billing is per execution. Functions suit short, event-driven tasks such as processing messages, reacting to file uploads or running scheduled jobs. They are the serverless compute option described in the cloud computing concepts module.
Choosing a compute type
The three types differ in control, management effort, start-up time and billing. The following comparison summarizes the differences.
VM, container or function?
Three workloads
A company has three workloads: a legacy accounting application that requires a specific Windows Server configuration; an online shop being rebuilt as a dozen microservices that the team wants to deploy identically in test and production; and a small task that resizes each image uploaded to a storage account. Which compute type fits each workload?
The legacy application needs control of the operating system, so it fits a virtual machine. The microservices need portable, consistent packaging and fast deployment, so they fit containers. The image-resizing task is short and triggered by an event (an upload), so it fits Azure Functions, which costs nothing when no images are uploaded.
Why do containers start faster than virtual machines?
Show answer
Containers share the host's operating system kernel, so they do not boot a full operating system as a VM does.
Exam Tips
Remember for the exam
- VMs virtualize hardware and give full OS control; containers share the host kernel and start in seconds.
- Functions run event-driven code with no infrastructure to manage and are billed per execution.
- Control and management effort decrease from VMs to containers to functions.