VM vs Container
j

Pradip Silwal

September 19, 2020

Virtualization

Virtualization is a technology which enables creation of multiple virtual computing environments on a physical computing machine. As opposed to traditional methods where a physical machine is used for a single server, virtualization allows  to create multiple computing instances. A software called hypervisor emulates the underlying hardware resources to each virtual machine. Hypervisor divides the physical hardware into separate pieces such that each virtual machine can have its own separate physical resources.

Virtualization enables efficient utilization of resources. When running a single server on a physical hardware, the resources may not be fully utilized. Creating multiple virtual machines enables for the optimal utilization of available resources. It is also easy to scale the servers easily, as another VM can be created on the same resources instead of buying new hardware and setting it up.

There are two types of hypervisors. Type 1, and type 2.

Type 1 Hypervisor

This is also called bare metal hypervisor. This type of hypervisor runs directly on host hardware. Since they run directly on the host hardware, virtualization using this hypervisor provides higher performance. They are mostly used by enterprise customers. VMware ESXi, Microsoft Hyper-V, and Citrix Hypervisor are some examples of this type of hypervisor.

Type 2 Hypervisor

Type 2 hypervisors are installed on existing OS. Thus they cannot have direct access to underlying hardware. They depend on the host OS for managing CPU, network, memory and storage resources. Due to this, it is less efficient than type 1 hypervisors. Some examples of type 2 hypervisors are, Oracle VirtualBox, VMware Workstation, and Microsoft Virtual PC.

Virtual Machines

Virtual Machine emulates the whole computer hardware which can be accessed by any application running inside the virtual machine. The virtual machines can have any type of operating system. Virtualization is the technology that enables us to run multiple virtual machines within the same hardware resources.

Let us look at type 2 virtualization. The lowest layer is the hardware layer. It’s where all the hardware resources such as processor, memory, storage, and graphics lie. There is an Operating System (OS) that is interacting with the hardware. This is called Host Operating System. This OS can be any OS like Windows, Linux, and macOS. On top of host OS there is a Hypervisor layer. This layer has a hypervisor software that enables virtualization of the hardware. The virtual machines run on top or hypervisor. Each virtual machine has its own OS.

Containers

Container is a package of software that contains everything that is required to run the application. It includes dependencies, libraries, OS, configurations and many more that are required by the application. Containers run as a process inside a linux system. Each container is a process that runs in its own namespace. Containerization achieves isolation of containers using namespaces. The examples of containerization engines are Docker, and Canonical LXD.

Namespaces

Namespaces facilitate isolation of a linux process. It abstracts the global resources such that the processes can have their own isolated global resources. There are 7 types of namespaces in linux.

PID

Provides Process ID isolation by providing an independent set of process id for each namespaces.

NET

Isolates network resources by virtualizing the entire network stack.

MNT

This isolates the mount point.

UTS

This isolates the hostname and domain name among the processes.

User

It allows a user to have root privileges inside a namespace while it has restricted privileges outside of that namespace.

CGroups

Cgropus also known as Control Groups is for resource limitation. It is implemented so that a specific process is not able to access more resources than what has been allocated to it.

Here, the first two layers are the same as type 2 virtualization. On top of the Host operating system there is a containerization engine that manages the containers. Containerization allows multiple containers to run in the same host operating system. Then the apps and services run within the container. This makes the apps and services independent of the host OS.

Comparison

Virtual Machines: Advantages

  • Highly secure and isolated from the host OS and from other VMs that are running on the same host OS.
  • It allows easy and effective provision of hardware resources.

Virtual Machines: Disadvantages

  • Since virtual machines are larger in size, it takes lots of resources from the host machine.
  • It is also slow to provision a VM; this makes VM difficult to scale up and down on demand.
  • It is difficult to migrate the app to a different environment as it is highly dependent on the operating system that it is running on.
  • A VM can be a waste of resources as not all the available resources may be used by the running application.
  • A VM uses all the allocated storage resources by itself.

Containers: Advantages

  • Are lightweight as it only contains necessary components required to run the applications.
  • Since they are independent of the host OS, they are easy to move across environments.
  • Since they are smaller, it takes a lot less CPU and Memory resources.
  • The lightweight feature enables faster deployment of containers.
  • It’s also easy to scale up and down.
  • Containers can share the storage resources.

Containers: Disadvantages

  • Since containers share the same host OS, they provide some level of isolation from other containers but not like that provided by virtual machines.
  • Containers are isolated in the process level using namespaces

Pradip is a recent graduate in Master of Science (Network Systems) from Swinburne University of Technology. He has a year of experience as an Android Application Developer at EB Pearls. He has good understanding in Azure Administration, Active Directory, and Computer Networking.

Pradip Silwal

Get connected with Pradip :

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Articles