What is a container, and how does it differ from a VM? Continuing on from the cloud terminology post I decided to go back to basics. As much for my own knowledge verification as for anything else.
Before going into a deep dive on the differences though I thought it might be worth starting at the basics. What are the components of a computer. Essentially there are four core components.
- CPU
- Memory
- Network
- Storage
On top of these you will install an Operating System, then one or more applications. These applications can be in isolation or can talk to each other through the OS or an Application Programmable Interface (API). The way that a user will interact with the applications is through a Graphical User Interface (GUI) via a keyboard, mouse, or touch screen.
A Virtual Machine takes the four key components and turns them into a file that then runs within another program. This creates a layer of abstraction between the underlying physical infrastructure and the VM. Why would you do this? Typically the physical infrastructure that is available today cannot be consumed by a single computer with programs running on it, and in fact lots of resources are wasted. By running multiple VM’s on a physical computer or server you can use more of those resources, giving a better use of money. From an environmental point of view this is also great as you need less physical tin, real estate, and associated power and cooling. Win Win so far.
So what are the downsides?
A VM still has lots of resources allocated to it, a full Operating System is required per VM which can be expensive, and boot times can still be quite high. Improvements in the underlying components though have resulted in some boot times dropping markedly. But you still need to deploy applications, keep them up to date through patching and have a fair amount of administrative overhead.
Along came containers
What is a container? Where a VM is an abstraction of the physical hardware a container is an abstraction at the application level. The container has the application and any dependancies packaged together. A single Operating System can then have multiple containers running on top, each in isolation from the next. This means you can have lots of applications with lower cost because you do not need to license multiple OS’s and boot time for the application is smaller because the footprint of the OS is smaller.
So which should you use? Well why not both together. Docker has a great article on the differences here.