Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of basic Concepts and underlying principles of Docker

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the sample analysis of the basic concepts and underlying principles of Docker. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Docker architecture diagram:

We illustrate the basic concepts of Docker according to the Docker architecture diagram.

1. The underlying principle of Docker

Docker is a Client-Server-structured system in which the Docker daemon runs on the host and is then accessed from the client through a Socket connection. The daemon receives commands from the client and manages the container running on the host. A container is a runtime environment, just like the container we mentioned earlier.

For example, the client (Client) and server (DOCKER_HOST) in the architecture diagram:

Send the command docker run hello-world

The Docker client forwards commands to the Docker daemon (Docker daemon) on the host

The Docker daemon receives the execution command and returns the command execution result

The Docker server (daemon) is responsible for managing the containers on the host.

As shown in the following figure:

Docker clients and daemons connect through Socket and can connect remotely or locally.

Socket description:

Two programs on the network exchange data through a two-way communication connection, one end of which is called a Socket. At least one pair of port numbers (Socket) is required to establish a network communication connection. Socket is the middle software abstraction layer for the communication between the application layer and the TCP/IP protocol family. It is a set of interfaces used to organize data.

2. Basic concepts commonly used in Docker

Image: the Docker image is similar to the image of a virtual machine, like a template, a read-only template for the Docker engine that contains the file system, through which container services can be created.

For example, an image can fully contain the Ubuntu operating system environment, and it can be called a Ubuntu image. An image can also have an Apache application (or other software) installed, and it can be called an Apache image. Multiple containers can be created through this image (the final run of the service or project is in the container).

Images are the basis for creating Docker containers. Through version management and incremental file systems, Docker provides a very simple mechanism to create and update existing images. Users can download a completed application image from the Internet and use it directly through the command. In short, applications need an environment to run, and mirroring is to provide such an environment.

(different classes can create different objects, and the same class can create multiple objects of the same type.)

(different images can create different containers, and the same image can create multiple containers of the same type.)

Container (Container): Docker uses container technology to run one or a group of applications independently and create them by mirroring them.

The Docker container is similar to a lightweight sandbox (because Docker is a virtual technology based on the Linux kernel, it consumes very few resources), Docker uses the container to run and isolate applications.

Containers create running instances from images, which can be started, started, stopped, and deleted, and these containers are isolated and invisible to each other.

The image itself is read-only. When the container starts from the image, Docker will create a writable layer on the top layer of the image, and the image itself will remain unchanged.

(at present, this container can be interpreted as a simple Linu shipping system.)

Repository: a warehouse is the place where images are stored.

Docker repositories are similar to code repositories, where Docker centrally stores image files.

According to whether the stored images are public or not, Docker repositories are divided into public repositories (Public) and private repositories (Private).

At present, the largest public repository is Docker Hub (Docker official Image Repository), which stores a large number of images for users to download. Domestic public repositories include image repositories such as Aliyun and NetEyun, which can provide stable domestic access (image acceleration).

Docker also allows users to create a private repository within the local network that can only be accessed by themselves.

After users have created their own image, they can use the push command to upload it to a specified public or private repository. In this way, the next time you use the image on another machine, you just need to pull the image from the repository pull.

Relationship between image and container:

3. The running process of run command

Let's take the example of running a hello-world image before.

Execute the docker run hello-world command, and the result is as follows:

$sudo docker run hello-world# appears as shown below Prove that Unable to find image 'hello-world:latest' locally # (local hello-world image not found) latest: Pulling (pull) from library/hello-world # (remote pull library/hello-world image) 1b930d010525: Pull complete # (pull completed) Digest: sha256:d1668a9a1f5b42ed3f46b70b9cb7c88fd8bdc8a2d73509bb0041cf436018fbf5Status: Downloaded newer image for hello-world:latest# (the above three lines are the signature information of the pull image) # Summary: because there is no hello-world image locally So a hello-world image is downloaded locally from the remote repository and a container is created to run. Hello from Docker # (the image is running) This message shows that your installation appears to be working correctly.# (this message indicates that your installation seems to be working properly. To generate this message, Docker takes the following steps:) To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with: $docker run-it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/

Tip: after you output this prompt, the hello-world image will stop running and the container will automatically terminate.

Flowchart of the execution of the run command:

4. Why is Docker faster than VM

(1) Docker has fewer abstraction layers than virtual machines.

Because Docker does not need Hypervisor to virtualize hardware resources (which is equivalent to creating a virtual machine using VMware), programs running on Docker containers directly use the hardware resources of the actual physical machine. Therefore, in terms of CPU and memory utilization, Docker will have obvious advantages in efficiency.

(2) Docker uses the kernel of the host and does not need Guest OS.

So when creating a new container, Docker does not need to reload an operating system kernel like a virtual machine. In order to avoid quoting, loading the operating system kernel and so on, which are more time-consuming and resource-consuming operations.

When creating a new virtual machine, the virtual machine software needs to load Guest OS, which is a minute-level process. Docker omits this process because it directly uses the host's operating system, so it only takes a few seconds to create a new Docker container.

As shown in the following figure:

Comparison table between Docker and VM:

This is the end of this article on "sample analysis of basic concepts and underlying principles of Docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report