I'm not clear on the difference between a virtual machine and a container. They both seem to be trying to accomplish the same thing. What makes them different, and why have containers risen in popularity in recent years?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
For completeness sake, your first listed 'main advantage' isn't something exclusive to containers, they just make it easier.
It's possible to do it with QEMU (done it before, direct boot of Linux in a barebones system (only hardware was VirtIO interfaces, no ISA, no legacy devices, etc) with nothing more than an init process (for proper powerdown support and a process reaper), the service being run, and SSH (for debugging)), Xen (same general concept as QEMU, just using PV domains, or you do nano-kernel OS-es (see for example documentation for running xenstored as a DomU instance)), and pretty much any other hypervisor that can be easily scripted which doesn't require you to emulate a full machine in the first place (which is admittedly not many others). I've even seen some software ported to run on RTEMS (single-process POSIX model, wicked fast boot times) for this type of thing. The difficulty there is setting them up in the first place, which isn't nearly as bad with containers.
The key difference is where the virtualization is happening. A virtual machine is virtualized at the hardware level (that is, it has virtual hardware), while a container is virutalized at the OS level (that is, the OS itself is virtualized).
This leads to a number of at times subtle, but often significant differences:
The last point is probably the biggest contributor to the rise of containers over VM's. Most hypervisors make you commit a fixed amount of resources to each VM, so it's hard to reliably over-provision and not unusual to have large percentages of your system not being utilized to the fullest. Containers are more easily flexible in that respect, so it's easy to over-provision, and much easier to ensure that everything that can be used on your system is being used.
Like Diane mentioned, VM is hardware emulator, but unlike Wine containers also do not translate system calls.
Containers come as a solidification of functionality which Linux already supports, chroot. / (root) in Linux being the very top level of the file system (and everything is a file) means your entire system can be redefined anywhere. No emulation, just moving the top level of your system.
Here's a great conference talk on how containers work under the hood and that helped me understand the difference between them and VMs
youtube.com/watch?v=8fi7uSYlOdc