Docker: Lightweight Containers vs. Traditional Virtual Machines
Software development and deployment models have changed drastically over the last few decades. While software development has transitioned from the classical waterfall to agile & scrum models, deployment techniques have moved to more lightweight and lean approaches as well.
Especially, the last couple of years have been a definitive and transformative phase for the DevOps (Development-Operations) industry as it has seen a radical shift from the traditional VM () model to a modern container-based approach. Let’s first look at the DevOps segment from a historical perspective and see how it has evolved over the years.
Virtual Machines
As the name itself suggests, a virtual machine represents a logical/software abstraction of a machine that can be used by end users as a physical machine. The virtualization can be done at platform level – thereby emulating a complete operating system or at the process level – restricting it to a single process.
In both cases, a virtualization layer acts as an intermediary to the host machine to request resources such as CPU, memory, hard disk etc. A hypervisor/ virtual memory manager (VMM) is the tool that typically provides this virtualization layer and is used to create, manage and maintain virtual machines running on a host. VirtualBox, Virtual PC and Parallels are some of the most commonly used hypervisors.
The ascent of virtualization over the years is unsurprising as it solves the a major business challenge – you can run multiple operating systems on a single machine thereby reducing both capital (CAPEX) and operation (OPEX) expenditures. Although virtualization started off as a software-only concept, several leading OEMs such as Intel, AMD and others adopted hardware-assisted virtualization~(aka accelerated virtualization) thereby providing an end-to-end virtualization environment, which provides significantly improved compute capacity. Virtual machines also help streamline the various operations aspects of deployment and maintenance including high availability, disaster recovery etc.
However, despite all the advancements in virtualization technology over the years, VMs still have the following challenges /disadvantages:
The overall efficiency of a virtualized machine does not match up to that of a physical machine, especially under peak load conditions that lead to intensive utilization of CPU, memory and other hardware resources. This is especially true in scenarios where a single physical machine is running multiple virtual machines.
Similarly, in the scenario where a large number of virtual machines reside on the same physical machine, there’s a greater risk for a single point of failure. Although VMs can be quickly restored, maintaining a standby server is a significant additional operation cost.
Multiple players offering proprietary virtualization solutions has meant that devops engineers need to ramp up on multiple tools, skills and configurations.
From an app development perspective, it can be quiet challenging for developers to ensure that their apps work uniformly across virtual machines of varying configurations.
Container-based Approach
While the advancements in virtualization technology have continued over the years, it’s still a resource-heavy proposition as each VM operates like a selfcontained system with its own resource needs.
In that sense, a more lightweight approach where logical entities can share and the operating system as well as associated resources if required. Therefore, ‘containers’ which are logical entities running on the same operating system as the host offer a more efficient alternative. Containers can be viewed as transparent clients that use the resources as it they were applications running on the host system.
While the concept of containers has been around for quiet some time, the containerization approach has seen a serious adoption when ‘Docker’ was introduced.
What is Docker?
To put it in simple words, Docker provides a containerized approach for building distributed applications. Unlike virtual machines that require a guest operating system to run on, Docker uses an abstraction engine called ‘Docker Engine’ which abstracts the operating system level details from the application.
Docker also offers ‘Docker Hub’ – a framework designed to promote rapid application development and deployment using the bottom-up component based approach.
Docker vs. Traditional Virtual Machines
The essence of Docker-based containers is that they eliminate the heavy lifting involved with setting up virtual machines and making sure your applications run seamlessly across multiple such instances. Therefore, application developers are abstracted from any platform specific details and administrators can leverage standard environments (called Docker images) without worrying about differences in terms of operating system versions, CPU and memory configuration etc.
Since Docker containers do not run a guest operating system, they usually are much quicker to start than virtual machines. Similarly, Docker is more effective when it comes to snapshotting your application into an image and deploying it across multiple environments – development, test and production.
However, it’s not necessarily an either/or proposition when it comes to picking between Docker containers and traditional VMs. In scenarios where you need total isolation from the host machine or you need to build a high availability cluster of multiple logical servers, VMs are still the preferred approach.
The best of both worlds
There’s also a growing trend that points to wider adoption of a hybrid approach that leverages Docker containers along with traditional VMs in tandem at enterprise data centers where using either approach alone does not suffice.