Containers vs Virtual Machines
Both can be used to run processes in isolation, but when to choose either?
Virtual machines provide the greater level of isolation. Each VM has its own operating system and therefore its own kernel. Although all VMs run on the host’s hardware, each of them has a physically assigned portion of these shared resources, even when the machine is idle.
Containers, on the other hand, all run on the host’s kernel, among any other process. They still run in isolation; to the process itself, it looks like it’s the only one running on the machine and its operating system. This is possible thanks to Linux features such as namespaces and control groups.
If you require a greater level of isolation or running a specific OS or Kernel, a VM might be the choice. If you need to optimise hardware resources, a container is likely your best option.