DEV Community

DevGraph
DevGraph

Posted on • Edited on • Originally published at blog.engineyard.com

Docker Vs Virtual Machines Explained

By Ritu Chaturvedi

Docker is a software solution for performing virtualization. With so many eyes on this cloud computing technology, it is hard to distinguish between Docker containers and virtual machines as two different technologies.

The main distinction between these two technologies is that VMs run as virtual environments on the same hardware, whereas Docker runs on virtualizations of the same operating system. We will be explaining this and other key differences in more detail throughout this article.

WHAT ARE VIRTUAL MACHINES

A VM is a simulated computer system. It runs on virtualized hardware in a “sandboxed” environment on a computer or server. The term ‘virtualized hardware’ refers to VMs without dedicated hardware. Instead, these VMs use an allotted portion of the same hardware system. Sandboxed environments do not have direct access to their host system’s operating system (OS), files, or hardware. In effect, running a virtual machine involves installing an entire operating system that runs dual-booted via a hypervisor, in parallel with or instead of your native operating system.

A virtual machine can perform tasks such as running applications and programs like a separate computer, making them ideal for testing other operating systems like beta releases, creating operating system backups, and running software and applications.

BENEFITS OF USING VIRTUAL MACHINES

• Multiple OS environments can exist simultaneously on the same host machine, isolated from each other.
• A virtual machine can offer an instruction set architecture that differs from real computers.
• They offer easy maintenance, application provisioning, availability, and convenient recovery.
• They’re integrated with established management and security tools.

POPULAR VM PROVIDERS

Here are some virtualization technologies that have gained much popularity in 2020:

Azure Virtual Machines - Azure Virtual Machines gives you the flexibility of virtualization for a wide range of computing solutions: development and testing, running applications, and extending your datacenter with support for Linux, Windows Server, SQL Server, Oracle, IBM, and SAP.
Hyper-V - Microsoft Hyper-V Server 2012 is a stand-alone product providing a simplified, reliable, cost-effective, and optimized virtualization solution.
Kernel Virtual Machine (KVM) - KVM is a Linux container (LXC) virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable host kernel module that provides the core virtualization infrastructure and a processor specific module.
Virtual Box - VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature-rich, high-performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2.
VMware Sphere - vSphere is the industry-leading compute virtualization platform and your first step to application modernization. It has been re-architected with native Kubernetes to allow customers to modernize the 70 million+ workloads now running on vSphere. Modern containerized applications can be run alongside existing enterprise applications in a unified and straightforward way, using vSphere with Tanzu.
AWS EC2 - Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, scalable compute capacity in the cloud. It is designed to simplify web-scale cloud computing for developers. It offers complete control of your computing resources and lets you run on Amazon’s proven computing environment.

WHAT ARE DOCKER CONTAINERS

Docker containers may seem similar to virtual machines, but there are some key differences. Instead of abstracting the hardware, containers abstract the OS. But to better understand container technology, we must first take a look at the Docker ecosystem.

To run containers on the Docker engine, we must first have a docker image, which can be created by the following steps:

• First, create a Dockerfile in the root directory of the application.
• After that, create a docker-compose.yml file for defining and running multi-container Docker applications.
• Then you can run the container image.

Containers allow a developer to package up an application with all of its necessary parts, such as libraries and other dependencies and deploy it as one package. The docker-compose file is responsible for managing these packages.

Virtual machines have a host operating system and a guest operating system inside each VM. The guest OS can be any OS, such as Linux or Windows, irrespective of the host OS. In contrast, Docker containers are hosted on a single physical server with the host OS shared among them. Sharing the host OS between containers makes them light and decreases the boot time. Docker containers are considered suitable to run multiple applications over a single OS kernel; whereas, virtual machines are needed if the applications or services are required to run on different OS.

BENEFITS OF CONTAINERS

• With the Container Runtime Interface (CRI) creation, you have many ways to store virtual machines and communicate through that interface in real-time.
• Because images run the same no matter which server or whose laptop they are running on, Docker is highly compatible and maintainable. That means less time spent setting up environments, debugging environment-specific issues, and a more portable and easy-to-set-up codebase.
• Continuous Deployment and Testing speed up the development cycles, and the application swiftly reaches the production environment.

• The higher portability of containers allows easy scalability and code migration, making it a great option for microservices.

DIFFERENCE BETWEEN PHYSICAL SERVERS & VIRTUAL MACHINES

A physical server, also known as a ‘bare-metal server,’ has system resources that are not shared. Each physical server includes memory, processor, network connection, hard drive, and an individual OS for running programs and apps.

Architecture

In traditional architectures, the operating system is directly installed on hardware devices, such as a rack-mount server, a blade server, etc. Therefore, there can only be one operating system, a Microsoft Windows platform, or a Linux platform. And there can also only be one application layer.

However, on virtual architecture, there is a virtualization layer between the underlying computer hardware and the various OS and applications on the system. This virtualization layer or hypervisor can also dynamically allocate physical hardware resources to each isolated virtual machine.

Security

Security management is more easily configurable in a VM than in a physical server. With physical servers, you have to build a system of protection for each server, depending on its computing capabilities and resources and the sensitivity of data that it stores.

On the other hand, a Virtual Machine can be protected based on a universal security model. Thus, security policies and procedures can be developed, documented, and implemented from a single pane of glass - that is, through the hypervisor dashboard.

Portability

One of the significant differences between physical servers and virtual machines lies in portability. You can easily move VMs across the virtual environment and even from one physical server to another with minimal input on your part. That is because VMs are isolated and have their virtual hardware, which makes a VM hardware-independent.

Moving your physical server environment to another location is a more resource-intensive task. In this case, you will need to copy all data stored on the server to a removable media, transport the media as well as all hardware resources that you have to a new location, and then re-install all of the system components on the new server. Essentially, you will have to rebuild a server from scratch.

Cost

Unless you use VMs on AWS EC2, building and maintaining a physical server environment can be quite expensive. That is due to the constant hardware and software upgrades, frequent system failures, and computer components and equipment breakdown, which are difficult or even impossible to repair.

At the same time, virtualization is considered a perfect option for enterprises that contain a large number of servers. A virtual server environment allows you to evenly distribute computing resources among all running VMs, thus ensuring capacity optimization for a minimal price.

Performance

This factor should be considered if your organization works with a large amount of data that needs to be processed continuously. Physical servers are far more powerful and efficient than VMs because VMs are prone to performance issues as a result of an overflow of virtual servers in a physical machine. Thus, a physical machine and a virtual machine, both having the same hardware and software resources and capabilities, cannot perform on the same level. If your organization runs operations that require the use of computing resources to the fullest extent, a physical server is an optimal choice.

Documentation & Support

There is more documentation for a virtual machine as compared to a physical one. Though it depends on the manufacturers and vendors, virtual machines still receive better and faster support for any problems you might have.

FAQS - DOCKER VS. VIRTUAL MACHINES

Q: Are Docker Containers Faster Than VMware Virtual Machines?
A: "Containers are lighter-weight, and they offer definite performance advantages in certain areas, like startup time. Depending on the type of workload you are contending with; however, containers may not be significantly faster than virtual machines." - Christopher Tozzi

• Q: Can You Run Docker In A Virtual Machine?
A: Yes, it's entirely possible to run Docker in a VM. Docker is a lightweight virtualization solution. It doesn't virtualize hardware so that you won't be affected by problems typical for nested VMs. However, port binding may be a bit tricky because you'll have to somehow connect your dev-env VM in VMware with Docker VM in VirtualBox.
See related posts here.

ENGINE YARD

Are you worried about how to migrate your application to containers! Don’t fret! Engine Yard makes it simple with predefined templates, detailed documentation, and our rockstar services team so you can easily containerize your applications without changing the source code and with no DevOps.

You can run Docker containers on utility instances through custom chef recipes.

The utility instances use EBS volumes that are backed up by the Engine Yard platform. That makes our Docker support useful for both stateless and stateful containers. For example, Memcache and Redis can save data to the EBS volume. Applications written in any language can be deployed on Engine Yard V5 through the supported use of Docker containers.

You can try out Engine Yard here.


Docker, virtual machine

Top comments (0)