Containers vs Virtual Machines: What's The Difference?by Iwan Price-Evans on Containers • June 15, 2022
Virtualization is a common term that describes how software is used to divide a single computer's hardware and make it available to multiple virtual computers. This has many benefits, the primary ones are IT efficiency, portability, and enhancing the application delivery lifecycle.
Containers and virtual machines (VMs) have become popular ways to virtualize computers but what is the difference between them?
What is a VM?
A VM emulates a physical computer and runs a full operating system and kernel. You can think of the kernel as the nuts and bolts of the operating system. A VM can emulate a specific hardware system. VMs can be created to exactly replicate a physical computer configuration.
VMs are managed by a lightweight software layer called a hypervisor. This is effectively a monitor that creates and runs VMs. The hypervisor allows the host computer to separate its operating system and applications from its hardware. This enables the host computer hardware to be divided into many VMs.
Each VM has its own operating system which can be any type, such as Windows, UNIX, Linux, or OSX. This virtualization enables different operating systems to be run on a single physical device. However, because each VM contains a full operating system they can be gigabytes in size.
What is a Container?
Containers are different from VMs in that they don't contain a complete operating system. Containers sit on top of the host operating system's kernel. They contain applications but only lightweight components of the operating system, such as services and APIs it might need.
Each container will share the host's kernel, binaries, and libraries, all of which are read-only. As a result of this lightweight implementation, containers are much smaller than VMs and can be only megabytes in size.
Containers are lightweight which makes it easy for development teams to create and destroy them as needed. This transitory and disposable design supports agile application development methods.
Features of Virtual Machines vs Containers
The main differences between containers and virtual machines are scale and portability.
As mentioned, containers provide a way to virtualize a single host operating system so that multiple workloads can be run on shared resources. Containers are lightweight and portable, whereas VMs use the hardware of a single device to run multiple instances of stand-alone operating systems. VMs are complete replicas of physical computers, and while still portable, they need large amounts of data storage.
Here we compare the features of both types of virtualization.
- VMs provide complete isolation from the host OS.
- A container provides lightweight isolation and therefore has less of a security boundary between it and the host OS.
- VMs run a full OS and don't rely on the host's kernel.
- Containers run on top of the host's OS and can be made more efficient by only configuring the services it needs.
- VMs can run any type of OS.
- Containers use the same OS as their host.
- VMs must be deployed by a hypervisor management tool.
- Containers can be deployed using tools like Docker or Kubernetes.
- VM operating system updates must be downloaded and applied to each VM instance. This can require a complete rebuild of the VM.
- The files that containers are configured to use must also be updated individually. However, because they are more lightweight this can be done efficiently and automated.
- VMs have a virtual hard disk (VHD) and store files locally (internally), or they can store files on an external location (SMB share).
- Similarly, containers can store files locally or on an SMB share.
- VM load balancing is performed by moving them to failover server clusters.
- Unlike VMs, containers don't move – they are started and stopped on server cluster nodes on demand.
- On failure, a VM can be switched to another server but will require a restart of the OS on the new server.
- Any container that fails is automatically recreated on one of the other cluster nodes.
- VMs use virtual network adapters.
- Containers use the host's networking adapter and share the host's firewall with other containers.