Docker containers and virtual machines

One of the common questions about Docker is the difference between it and VM (Virtual Machine).

In terms of cloud infrastructure, virtual machines have become the preferred standard for many of its advantages. But what if you have a lighter, more economical and scalable virtual machine alternative. This is Docker .

Docker is a container-based technology that allows you to develop distributed applications. In this blog post, I will explain the difference between virtual machines and Docker containers.

What is a virtual machine?

A virtual machine is a system completely similar to a computer.

In short, it makes possible something that can run on many separate computers (ie one computer) on the hardware. Each virtual machine needs its underlying operating system and then virtualizes the hardware.

What is Docker?

Docker is a tool that uses containers to simplify the creation, deployment and operation of applications. It binds the application and its dependencies in the container.

Docker and VM

Now, I will tell you the significant differences between Docker containers and virtual machines. Well, their operating system support, security, portability and performance are significant differences.

So let us discuss each of these terms one by one.

Operating system support

Tradition and new generation

Virtual machines and Docker containers support operating systems very differently. From the image above, you can see that each virtual machine has its guest operating system on top of the host operating system, which makes the virtual machine heavy. On the other hand, Docker containers share the host operating system, which is why they are lightweight.

Sharing the host operating system between containers makes them very lightweight and helps them boot in seconds. Therefore, compared with virtual machines, the overhead of managing the container system is very low.

The docker container is suitable for situations where you want to run multiple applications on a single operating system kernel. However, if you have applications or servers that need to run on different operating system versions, you need a virtual machine.

Safety

Virtual machines do not share the operating system, and there is strong isolation in the host kernel. Therefore, they are safer than containers. Containers have many security risks, and because they have a shared host kernel, they have vulnerabilities.

In addition, because Docker resources are shared and there is no namespace, an attacker can use all containers in the cluster even if they have access to one container. In a virtual machine, you cannot directly access resources, so the hypervisor can restrict the use of resources in the virtual machine.

portability

Docker container does not have a separate operating system, so it can be easily ported. The container can be ported to other operating systems and can be started immediately. On the other hand, the virtual machine has a separate OS, so compared to the container, it is difficult to migrate the virtual machine, and because of its size, it takes a lot of time to migrate the virtual machine.

For development purposes where applications must be developed and tested on different platforms, Docker containers are ideal.

performance

It would be unfair to compare virtual machines and Docker containers because they are both used for different purposes. But Docker's lightweight architecture has less resource occupancy functions , so it is better than virtual machines. As a result, compared to virtual machines, which containers can be started very quickly, and resource usage depends on the load or traffic in them.

Unlike virtual machines, there is no need to permanently allocate resources to containers. Compared with virtual machines, expanding and copying containers is also an easy task, because there is no need to install an operating system in them.

in conclusion

The following table summarizes the differences between virtual machines and Docker containers.

virtual machine Docker container
Hardware-level process isolation Operating system level process isolation
Each virtual machine has a separate operating system Each container can share the operating system
Start in minutes Start in seconds
The virtual machine is only a few GB The container is lightweight (KB/MB)
Off-the-shelf VMs are hard to find Pre-made Docker containers are easily available
Virtual machines can be easily moved to new hosts The container is destroyed and recreated instead of being moved
It takes a relatively long time to create a virtual machine The container can be created in a few seconds
More resource usage Reduce resource usage

Guess you like

Origin blog.csdn.net/allway2/article/details/109253719