Docker - Introduction

Table of contents

Development History

origin

virtual machine

container

Docker

overview

Docker Containers VS Traditional VMs

Operating principle

 Docker composition

run process

reference


docker

Development History

origin

One of the most troublesome things encountered in environment deployment during software development is environment configuration. Under normal circumstances, if we want to ensure that the program can run, we need to set up the operating system and install various libraries and components. For example, to run a Python program, the computer must have a Python engine, various dependencies of the program must be installed, and even specific environment variables must be configured. Suppose you have two programs that need to be deployed on the same server, one requires software based on Python 2.0 and the other is based on Python 3.0, then it is easy to cause confusion in deployment. Because different versions of Python modules may be incompatible with each other, and libraries on different development environments also require additional configuration. If you want to deploy many programs, and the development environment and deployment environment are different, you can imagine how troublesome the configuration is.

In order to better port the software from one environment to another, the root cause of the problem must be solved, so how to migrate the exact same original environment when porting the software?

virtual machine

Virtual machines are a solution for migrating environments. A virtual machine is essentially a piece of software in which we can run another operating system. For example, if we want to run a Linux system on MacOS, we install a Linux image on the computer and use a virtual machine to open the image to create a mirror-in-mirror. This solution is very convenient. If you want a new environment, you can install the image, and then use a virtual machine to open it. You don’t want to delete it directly. But this solution has several disadvantages:
 

  • Occupies a lot of resources: The virtual machine needs to install the entire operating system, which naturally consumes a lot of memory and hard disk space. If we only need to run 1MB software, sometimes we have to install several G environments to run it.
  • Redundant running steps: The virtual machine is installed with a complete system. Every time you run the program, you need to follow the steps step by step. It is very inconvenient to open the system, log in to the user, and other cumbersome steps.
  • Slow running speed: In order to run software in a specific environment, the virtual machine must first run the system, and the system often occupies a lot of resources (network, GUI, IO, etc.), which will naturally affect the running speed.
     

container

In order to solve these shortcomings of virtual machines, Linux has developed another virtualization technology: Linux containers. Instead of simulating a complete operating system, Linux containers isolate processes. In other words, a protective layer is applied outside the normal process. For the process in the container, the various resources it touches are virtual, so as to achieve isolation from the underlying program. Since containers are process-level, they have more advantages than virtual machines:

  • Occupies less resources: The container only occupies the required resources, and does not occupy those resources that are not used. Compared with installing a complete operating system on a virtual machine, the container needs to consume much less space.
  • High resource utilization rate: Virtual machines are all exclusive resources, and the computer needs to allocate resources for each virtual environment separately, which not only takes up a lot of space, but also has a low resource utilization rate. Containers can share resources to maximize resource utilization.
  • Fast running speed: The application in the container is a process of the underlying system, so starting the container is equivalent to directly running a process of the local machine instead of a complete and bloated operating system, which is naturally much faster.

Docker

overview

Docker is a package of Linux containers that provides an easy-to-use container interface, and it is currently the most popular Linux container solution. Docker packages software code and its dependencies into a single file. By running a single file, a virtual container is generated. In this virtual container, no matter how the local operating system is different, this container can run as usual. In short, it can help users better create and use containers, so that the same code can run normally on different environments.

Docker allows developers to package their applications and dependencies into a lightweight, portable container, which can then be distributed to any popular Linux machine, and can also be virtualized.

Note :

  • Docker is an open source application container engine, based on  the Go language  and open source in compliance with the Apache2.0 protocol.
  • Docker has been divided into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition) since version 17.03. We can use the Community Edition.

Docker containers vs traditional VMs

Comparison of virtual machine and Docker container architecture:

 

 Performance comparison between virtual machine and Docker container:

Operating principle

The running logic of the Docker container is shown in the figure below. Docker uses the client/server (C/S) architecture mode, and the Docker daemon (Docker daemon) as the Server side receives requests from the Docker client and is responsible for creating, running, and distributing Docker containers. The Docker daemon generally runs in the background of the Docker host, and users use the Docker client to directly interact with the Docker daemon.
 

 Docker composition

  • Mirroring: Docker mirroring is a special file system. In addition to providing programs, libraries, resources, configuration and other files required for container runtime, it also includes some configuration parameters prepared for runtime. Images do not contain any dynamic data, and their contents are not changed after they are built. Images can be used to create Docker containers, and users can use existing images on the device to install multiple identical Docker containers.
  • Container: The running instance created by the image, Docker uses the container to run the application. Each container is an isolated and secure platform. We can think of the container as a lightweight Linux operating environment.
  • Mirror warehouse: a place where mirror files are stored centrally. After the user creates the image, he can upload it to the public warehouse or private warehouse. When he needs to use the image on another host, he only needs to download it from the warehouse.

run process

  1. Docker client: a client used to establish communication with the Docker daemon (Docker Daemon). The Docker client only needs to send requests to the Docker server or daemon process (Docker build, Docker pull and Docker start instructions), and the server or daemon process will complete all the work and return the result.
  2. As shown in the orange process, executing the Docker build command will build an image based on the Docker file and store it on the local Docker host.
  3. As shown in the blue process, executing the Docker pull command will pull the image from the cloud image repository to the local Docker host or push the local image to the remote image repository.
  4. As shown in the black process, executing the Docker start command will install the image into the container and start the container.
  5. Docker host: A physical or virtual machine used to execute the Docker daemon and containers.
  6. Docker daemon: Receive and process requests sent by Docker clients, monitor Docker API requests and manage Docker objects, such as images, containers, networks, and data volumes.

reference

(48 messages) What is a Docker container? (Comprehensive understanding of usage)

Guess you like

Origin blog.csdn.net/yeyaozhifengqi/article/details/130406761