Docker container vs. virtual machine (VM) comparison

Docker is an open source application container engine. Docker can deliver software quickly by separating the application from the underlying infrastructure.

The operation of traditional virtual machines requires high resources, including disk space, memory, and processor performance. Each virtual machine requires a full copy of the operating system and applications, which has some overhead in resource utilization and startup time.

Container technology is a further evolution in the field of virtualization, which adopts a more lightweight virtualization method. Container technology utilizes the containerization function of the operating system (such as Linux containers), and realizes the isolation of applications and the virtualization of the operating environment by isolating the namespaces, file systems, and resource control groups (cgroups) of processes.

As a mainstream tool for creating containers, Docker has developed rapidly in recent years. Its advantage is that it allows developers to encapsulate various applications and application dependent files required by the enterprise in Docker image files, and then run them on any physical device (Linux device or Window device) etc.) to realize virtualization by installing and running on it, so that the application program can be completely separated from the underlying device, and can be flexibly migrated and deployed between physical machines, so that the operation and maintenance engineer can get rid of the tedious environment deployment, which greatly improves the work efficiency and reduces the deployment time. potential risks in the process.

Docker containers have the following four characteristics:

Lightweight: Docker containers are based on the virtualization technology at the operating system level. Compared with traditional virtual machines, containers are more lightweight. Each container shares the host's operating system kernel and contains only the application and the dependencies it needs to run, so containers start and stop very quickly.

Isolation: Each Docker container is isolated from each other and has its own file system, process space, and network interface. This means that the containers are independent of each other and do not affect each other. You can run multiple containers on the same host at the same time, and each container is like an independent virtual environment.

Portability: Docker containers can run on different operating systems and cloud platforms, and are highly portable. An application and its dependencies inside a container are packaged into a self-contained, portable unit that can be easily deployed and migrated between development, test, and production environments.

Scalability: Docker containers can be easily scaled horizontally. By using container orchestration tools (such as Docker Compose, Kubernetes, etc.), multiple container instances can be automatically or manually started, stopped, and managed according to demand to meet different load requirements.

Docker Containers vs Virtual Machines (VMs)

Docker containers and traditional VM technologies are different in technical implementation. The following figure shows the logical composition of VM and Docker containers:

Virtual machine (VM):
Hypervisor is used to provide a running platform for virtual machines and manage the operation of the operating system in each VM. Each VM must have its own operating system, applications, and necessary dependent files.

Docker container:
use the Docker engine for scheduling and isolation, which improves resource utilization and allows more container instances to run under the same hardware capability; each container has its own isolated user space.

 

Comparison of virtual machines and Docker containers

Compared with VM, Docker container, as a lightweight virtualization method, has the following significant advantages in terms of application:

  • Docker containers can be quickly started and stopped in seconds, which is significantly improved compared with traditional virtual machines.

  • Docker containers have low requirements on system resources, and thousands of Docker containers can run on the same host at the same time.

  • Docker containers facilitate users to obtain and update application images through Git-like operations.

  • Docker containers realize automatic creation and flexible deployment through Dockerfile configuration files, improving work efficiency.

  • Apart from running the applications in it, the Docker container basically consumes no additional system resources, ensuring application performance while minimizing system overhead.

The following figure can intuitively understand the difference between the Docker container and the traditional VM method:

 

The five components of Docker

Mirror build:

The basis of a Docker container is a Docker image, which is a read-only template that contains the file system and dependencies needed to run an application. A mirror can be created by writing a Dockerfile and running a build command. The steps of building a mirror are defined in the Dockerfile, such as installing software packages and configuring the environment.

Container creation:

Containers can be created based on specific images by using the Docker command-line tool or the Docker API. When creating a container, you can specify the name of the container, network settings, port mapping and other parameters. Each container has a unique ID and an isolated runtime environment.

File system isolation:

Docker containers use technologies such as namespaces and control groups (cgroups) of the Linux kernel to achieve file system isolation between containers. Each container has its own view of the file system, but they share the kernel of the host operating system.

Run the application:

Applications and processes inside containers can be executed in an isolated runtime environment. Docker containers can run any application that can be executed in the operating system, such as web servers, databases, etc. Applications inside containers can provide services through network communication with the host or other containers.

Container management:

Docker provides a set of command-line tools and APIs for managing and monitoring containers. These tools can start, stop, restart, delete containers, and more. At the same time, Docker also supports container orchestration tools, such as Docker Compose and Kubernetes, which can be used to automatically manage and expand multiple containers.

Here are some common containerization technologies:

Docker: Docker is one of the most popular containerization platforms out there. It provides a standard container format and runtime environment that enables developers to package an application and its dependencies into a self-contained, portable container. Docker provides powerful tools and features for building, deploying, and managing containerized applications.

FinClip applet container: FinClip is a mobile-focused applet container platform. It provides a small program containerization solution, enabling developers to embed and run small programs in mobile applications. FinClip provides a series of APIs and tools, enabling developers to integrate applets into mobile applications in a containerized manner and interact with the functions of mobile applications.

Kubernetes (K8s): Kubernetes is an open source container orchestration platform for automating the deployment, scaling, and management of containerized applications. Kubernetes provides functions such as container orchestration, service discovery, load balancing, and automatic scaling, enabling developers to run containerized applications in a reliable and elastic manner.

Apache Mesos: Apache Mesos is a distributed system kernel that provides resource management and task scheduling functions. It supports the deployment and management of containerized applications and can be integrated with a variety of container runtimes.

Cloud Foundry: Cloud Foundry is an open source containerized platform for building, deploying and managing applications. It provides a container-based development and runtime environment that supports multiple programming languages ​​and application frameworks.

LXC (Linux Containers): LXC is a lightweight virtualization technology based on the Linux kernel for containerization. It provides a way to isolate processes into independent namespaces to achieve application isolation and resource management.

These technologies have their own characteristics and application scenarios, but their common goal is to provide a convenient, portable and scalable containerized environment to simplify the deployment and management of applications, and provide higher resource utilization and reliability.

Guess you like

Origin blog.csdn.net/Lydiasq/article/details/130977862