What is the difference between containers and virtual machines, and when would you choose each?
What the interviewer wants to hear
- VMs virtualize hardware and run a full guest OS on a hypervisor
- Containers share the host kernel and isolate processes with namespaces and cgroups
- Containers start faster and are lighter, so density is higher
- VMs give stronger isolation and can run different OS kernels
- Common pattern: containers running on top of VMs in the cloud
Model answer
A virtual machine runs a complete guest operating system on a hypervisor, so each VM has its own kernel, drivers and boot process. A container is just an isolated process on the host: it shares the host kernel and uses namespaces for isolation and cgroups for resource limits. Because of that, containers start in seconds, use less memory and pack more densely, and the same image runs the same way on a laptop and in production. VMs give stronger isolation, which matters for untrusted multi-tenant workloads, and they can run a different OS such as Windows next to Linux. In practice in the cloud we use both: Kubernetes nodes are VMs, and our services run as containers on them. I choose plain VMs for legacy apps, special kernels or licensed software, and containers for most modern stateless services.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Cloud Engineer questions
- Explain the difference between IaaS, PaaS and SaaS with an example of each.
- What is a VPC and what are its main building blocks?
- Explain IAM users, groups, roles and policies. When would you use a role instead of a user?
- How would you make a simple web application highly available in the cloud?
- What pricing models do cloud providers offer for compute, and when would you use each?
- What is Infrastructure as Code and why do teams use it instead of the cloud console?
- Explain metrics, logs and traces. How does each help you run a cloud application?
- How does a CDN work, and what should you consider when caching content with one?
- Compare block, object and file storage in the cloud. Give a use case for each.