What is docker? What are the advantages and disadvantages of docker?

The idea of ​​Docker comes from the container. What problem does the container solve? On a large ship, the cargo can be arranged neatly. And all kinds of goods are standardized by the container, and the container and the container will not affect each other. Then I don’t need a ship dedicated to transporting fruits and a ship dedicated to transporting chemicals. As long as these goods are well packed in containers, I can transport them all in a big ship.

Introduction to docker

Docker is an open source application container engine and a lightweight container technology. Docker supports compiling software into an image, and then configures various software in the image and publishes the image. Other users can use this image directly. This image in operation is called a container, and the container startup is very fast.

Docker core concept

docker host (Host): the machine on which the Docker program is installed (Docker is directly installed on the operating system);
docker client (Client): the client uses the Docker
API (https://docs.docker. com/reference/api/docker_remote_api)
communicates with the Docker daemon.
docker registry: used to store various packaged software images;
docker images (Images): Docker images are templates for creating Docker containers.
Docker container (Container): The instance after the image is started is called a container; the container is an independently running application or a group of applications. The
image is a static structure and can be regarded as a class in object-oriented, and the container is an instance of the image .

The difference between docker and virtual machine

Virtual machine is also a kind of virtualization technology. The biggest difference between it and Docker is that it is implemented by simulating hardware and installing an operating system on the hardware.

To start a virtual machine, you need to start the operating system of the virtual machine first, and then start the application, this process is very slow;
and starting Docker is equivalent to starting a process on the host operating system.

A virtual machine is a complete operating system, which requires a lot of disk, memory, and CPU resources. One machine can only open dozens of virtual machines.
And Docker is just a process. You only need to package the application and related components. It takes up very few resources at runtime. One machine can open thousands of Dockers.

Advantages of docker

1. Easy to deploy

You must still have the impression that when we first started learning programming, setting up the environment often took us several hours, and one of the small problems may take a long time to solve. You will also get help from other members of the team regarding environment construction. With the container, this becomes very easy. Your development environment is just the address of one or several container images, and at most you need an execution script to control the deployment process. Or further put your environment mirror and mirror script into a git project, publish it to the cloud, and pull it locally when needed.

2. Deployment security

When we receive a bug feedback, most of the time the first reaction in our hearts must be "my local is good"! This situation occurs because of the inconsistency of the environment. Our debugging during the development process often cannot guarantee the problems of other environments, but we have to pay for this. This is really an annoying thing. With containers, this will rarely happen. We can use container technology to keep the development environment, test environment, and production environment unified in version and dependencies, and ensure that the code is executed in a highly unified environment. The unification of the test environment can also solve the environmental requirements of the CI process.

3. Good isolation

Whether it is development or production, often we may need to run multiple services on one machine, and the dependency configuration required by each service is not the same. If two applications need to use the same dependency, or between the dependencies required by two applications There will be some conflicts, and problems can easily occur at this time. Therefore, it is better to isolate different services provided by different applications on the same server. Containers have a natural advantage in this respect. Each container is an isolated environment. You can provide all the services required by the container and the container can rely on it.

4. Fast rollback

The previous rollback mechanism of the container generally needs to be redeployed based on the previous version of the application and replace the current problem version. In the initial era, it may be a complete development to deployment process, and it often takes a long time to execute this process. In a git-based environment, it may be to roll back a certain historical commit and then redeploy. These are not fast enough compared with the container technology, and may cause new problems (because it is based on the modification of the new version). The container technology is born with a rollback attribute, because each historical container or image will be saved, and it is very fast and simple to replace a container or a certain historical image.

5. Low cost

This may be one of the most obvious and useful advantages. Before the emergence of containers, we often needed a new server or a virtual machine to build an application. The purchase cost and operation and maintenance cost of the server are very high, and the virtual machine needs to occupy a lot of unnecessary resources. In contrast, container technology is much smaller and lighter, and only needs to build the dependencies required by the application inside a container. This is also the main reason for the rapid development of container technology.

6. Lower management cost

With the development of the big environment, the cost of using and learning docker and other containers is also decreasing, becoming the choice of more developers and enterprises.

Docker disadvantages

1. Isolation

Virtual machine technology based on hypervisor is better than container technology in terms of isolation. Their system hardware resources are completely virtualized. When a virtual machine has a system-level problem, it will not spread to the same host. Other virtual machines. But containers are different. Containers share the same operating system kernel and other components. Therefore, when an attack occurs, it is easier to affect other containers through the underlying operating system. Of course, this problem can be solved by deploying containers in the virtual machine, but this will lead to new problems, such as increased costs and the following problem: performance.

2. Performance

Regardless of whether it is a virtual machine or a container, different technologies are used to encapsulate and isolate the application to a certain degree. A lot of efforts have been made to reduce the coupling between applications and applications and between applications and environments. Then, it will generate more network connection forwarding and data interaction, which will not be too obvious on a low-concurrency system, and often will not become an application bottleneck (may be scattered on different virtual machines or servers ), but when the container under the same virtual machine or server needs higher concurrency support, that is, when the concurrency problem becomes an application bottleneck, the container will magnify this problem. Therefore, not all application scenarios are suitable for Of container technology.

Guess you like

Origin blog.csdn.net/weixin_43888891/article/details/112759045