How is a container different from a virtual machine? When would you choose one over the other?
What the interviewer wants to hear
- Containers share the host kernel; VMs have their own guest OS
- Containers are lighter and start faster
- VMs give stronger isolation
- Namespaces and cgroups provide container isolation
- Choice depends on isolation, OS needs and density
Model answer
A virtual machine runs a full guest operating system on top of a hypervisor, so each VM has its own kernel. A container is just an isolated process on the host: Linux namespaces give it its own view of processes, network and filesystem, and cgroups limit its CPU and memory. Because containers share the host kernel, they are much smaller, start in seconds or less, and you can pack many more on one machine. VMs give stronger isolation, which matters for untrusted multi-tenant workloads, or when you need a different kernel or operating system such as Windows on a Linux host. In practice we often use both: containers for applications, running inside VMs or managed nodes in the cloud for an extra security boundary.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy DevOps Engineer questions
- What does DevOps mean to you, and how is it different from a traditional operations team?
- Walk me through the stages of a typical CI/CD pipeline you would build for a web service.
- What is Infrastructure as Code and why is it better than creating resources by clicking in the cloud console?
- Explain how a Deployment, a Service and an Ingress work together to expose a web app in Kubernetes.
- Compare trunk-based development with GitFlow. Which would you choose for a team that deploys several times a day, and why?
- Walk me through what happens when you run docker run -p 8080:80 nginx:1.27 on a fresh machine.
- What is the difference between monitoring and observability, and what are the main signals you would collect for a web service?
- How does a load balancer use health checks, and what makes a good health check endpoint?
- Terraform and Ansible are both called infrastructure as code. How do they differ, and when would you use each?