Containers and Virtual Machines
Cloud service providers (at the IaaS and PaaS level) use virtual machines to serve their clients. The use case is obvious; VMs give you the ability to scale vertically and even horizontally, provide isolation for security, and can be tweaked in many other ways. Clients purchasing such VMs for use get to avoid the overhead of managing the actual hardware (especially servers) and can make use of the powerful layer of abstraction VMs on the cloud provide.
Sounds good, right? However, VMs are essentially full operating systems at your disposable. If you are a small-scale developer, it’s likely that you only host a couple of apps on the cloud service provider. It’s also likely that you have a few more applications hosted on other service providers.
Now consider that you basically have the entire VM with it’s operating system and other resources and binaries dedicated to hosting one or two apps at a time.
Besides the obvious inefficiency for this use case (the VM itself tends to take more CPU and memory than your application!), the costs for running that heavy setup is passed down to the consumer. You.
But wait, can’t we apply the same ideas used to move from host OSes to VMs? Something to… containerize the application and isolate it, but not reserve all that low level weight. Something like this:
Well, until a couple of years ago it was difficult and inefficient to implement container solutions like this, however improvements to the Linux kernel (and more) have given programmers more control over application isolation.
Today containers have become a popular and powerful abstraction for efficiently hosting small-medium applications. However they do have their downsides compared to more traditional VMs.
VMs vs Containers
For one, VMs are old enough that they are fairly standardised; they behave predictably, like having a real machine. Containers, being newer, are not very standardised in the industry yet.
They are also locked into using their host OS and kernel, compared to VMs where you are free to run your own image, and resources are accessed through virtual interfaces.
VMs also tend to be opaque to the host OS; it cannot optimise things like free block memory under the VM’s control. Containers appear as normal processes to the host OS, and the OS is free to do it’s job.
Even with those limitations, the extremely low overhead of containers mean they are widely used today. They start and close quickly and responsively. Nearly all big PaaS providers have support for containerization now.
The most famous industry container tool today is Docker, and if you have access to one of the later linux kernels that support containerization, do give one of them a try. The benefits and flexibility containerization provides cannot be overstated.