What is Docker and Virtual Machine
Virtual Machine is defined as a compute resource and works like a physical computer running in a completely isolated environment. When creating a virtual machine on a physical host, it is necessary to allocate some capacity of physical hard disk and memory to the VM. Each virtual machine has a separate CMOS, hard disk, and operating system, and uses software (Hypervisor) to run programs and deploy applications.
There is some famous virtualization software such as VMware, Microsoft Hyper-V, Citrix XenServer, and Oracle VirtualBox.
Docker is different from virtual machine. It is a lightweight and standalone virtualization software aiming to help you in developing, deploying, monitoring, and running applications in a Docker Container with all their dependencies. Docker can run across both Windows- and Linux-based platforms, and containers don’t need to embed a complete OS.
The commonly known container tools are Linux Containers (LXC), Docker, Kubernetes.
What's the difference: Docker vs VM
This part will describe the differences between Docker containers and virtual machines such as their OS support, security, performance and portability.
1. Operating System Support
The OS support is different between Docker containers and virtual machines. Virtual machine has the guest operating system above the host operating system, and Hypervisor virtualizes the hardware resource, which causes the heavyweight of VM.
However, Docker containers sit on the top of the physical host and share the host OS resource. They don’t require a complete operating system, and only need a small-scale environment like a sandbox, so they are light weight generally around 5-100 MB.
Each virtual machine has an isolated operation system, so it’s more secure with their standalone kernel compared to Docker containers. Docker container shares the host kernel, so it’s risky to offer root access to applications and run them with administrative premises since the entire host system is capable to be hacked by a single infected application.
For the important and large amounts of data, you’d better backup virtual machines in the production environment.
Virtual machines are more resource-intensive as they need to load the entire OS to start, which leads to poor performance.
The architecture of Docker containers is lightweight and less resource-intensive than virtual machines. They can start up quickly and have a high performance with sharing the host operation system.
In the case of virtual machines, resources like CPU, memory, and I/O may not be allocated permanently to containers — unlike in the case of containers, where the resource usage with the load or traffic.
Virtual machines require more memory space to store data and are more heavyweight. The VM ported process is more complicated across multiple platforms.
Docker without isolated operation system can be migrated and installed easily. The packages are self-contained and containers can be deployed across different platforms in less time. It’s more convenient for Docker to run applications in any environment.
A table to illustrate the major differences between Docker and Virtual Machine.
How to choose Docker containers or virtual machine
After familiar to the differences, which one do you choose?
For application or system function testing, Docker is the ideal choice. It allows you to test your software or application comprehensively on different operating systems, and it can respond to your services quickly with a relative low cost. If you are implementing a distributed architecture with each application run as a microservice, then Docker is ideal for deploying these kinds of applications.
If you need to run multiple applications or operating systems in a production environment and want to have an absolutely independent and secure virtual environment, virtual machines are the best choice for you. Virtual machines allow you to leverage the resources of hardware by expanding the number of machines and often store a lot of important business data. Any human errors and unexpected disasters can cause business interruptions, so it is important to choose the right virtual machine backup solution.
Regardless of which tool you choose, both docker and virtual machine can improve server utilization and efficiency, and reduce overall deployment costs. Or you can combine the two depending on your needs to create a better and efficient working environment.
Frequently asked questions about containers and VM
Q: Can you run docker in a virtual machine?
A: Since VMware and Docker deal with virtualization at different levels, they are not strictly competing technologies, but are complementary technologies as well. It is possible to use them in tandem, and many organizations do so. You can therefore run Docker in an OS such as Ubuntu or VMware’s Photon, running on a VMware ESXi virtual machine.
Q: Will Docker replace VMware?
A: Docker container is more agile and fast to deploy or test their code or applications, and you can deploy containers on bare metal, virtual machines, AWS, Azure or other production environment with lower costs. For use cases where greater security is required, virtual machines might still be a superior technology.
For Docker and virtual machine, they are different from each other. In this article, there are detailed introduction of differences between Docker containers and virtual machines. For virtual machine, it offers a secure environment to run the multiple operating system. On the other hand, Docker containers are ideal to test applications and codes.