In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the overall structure and startup process of Docker registryV2". In daily operation, I believe many people have doubts about the overall structure and startup process of Docker registryV2. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "the overall structure and startup process of Docker registryV2". Next, please follow the editor to study!
Overview of Docker registry
To explain Docker registry in one sentence is: a remote warehouse that stores docker image. In the process of using docker, we will definitely use docker Registry. When we use docker's pull command (download image), or run an image that is not available locally, docker engine will download the corresponding image from the default repository.
Currently, the default repository of the docker pull command is the official repository of docker, which leads to a problem that the speed of downloading images is slow. Therefore, in a large distributed docker cluster, a private docker registry is usually configured, which can improve the download speed of the image, thus improve the startup speed of the application, and facilitate the management of images.
The installation of docker registry is also very simple. Docker has encapsulated registry in a docker container. We just need to download this container, launch it, and then use it, which is very convenient. However, in this way, there can only be one registry. In a slightly larger cluster, single point of failure and performance bottleneck are more prominent, so it is imperative to expand to a highly available distributed structure, so many companies have done a lot of work in optimizing registry. At present, there are VMware's Habor [1] and JD.com 's speedy [2].
Development history of Docker Registry
-on March 13, 2013, docker had its first release on github [3]
-on July 3, 2013, docker released docker registry v1 [4] on Githubs
-on January 30th, docker registry v2 (project named docker distribution) had its first release and stopped updating docker registry v1 [5]
When using docker registry v2, it should be noted that only docker1.6 version or above supports registry v2, which does not mean that only v2 version can be used after 1.6. as we can see from the source code, docker Engine will automatically determine whether the remote repository is v1 or v2 version when downloading the image, thus using a different download strategy. Let's talk about the difference between v1 and v2 download strategies.
Figure 1 v1 serial download layer
We know that a docker image is made up of a lot of layer. The download process of registry v1 is shown in figure 1. When downloading the image, it is also downloaded with layer as the smallest unit. In the v1 era of docker image, the image structure has a linked list organization. When you download a layer, you can get the parent information, and then download parent layer. This structure is obviously not efficient, so in v2, the structure has been changed. All the layer information is stored in the manifest file of image, so that all the layer information can be downloaded in parallel, improving the download efficiency, as shown in figure 2.
Figure 2 v2 upgrade to parallel download layer
There are also changes in the development language used, from python to go.
Docker registryV2 overall architecture diagram
Fig. 3 docker registry 2.0 framework [6]
From the architecture diagram, we find that the architecture of registry v2 is very simple, and its core is a web server. From reading the source code, we will also find that the specific implementation is http.Server in the net/http package of go language, which is bound to the rest interface when registry is initialized. The request triggers the corresponding handler,handler and fetches the specific data from the backend storage and writes it to the response. The process is also easy to understand.
Analysis of Registry startup source code
Let's talk about the startup process of registry. This is the first time I have read the source code of an open source project. I will also talk about how I read the source code as a novice.
Since registry runs as a docker container, it depends on how it starts, of course, first look at its Dockerfile
Figure 4 Dockerfile
Two main things have been done:
1. Copy the code into the container
two。 Compile to a binary executable file
3. Specify program entry
When we run docker run-p 5000 registry 5000 registry:2, the startup command inside the container is actually registry serve / etc/docker/registry/config.yml
Enter the project to find the main function, and find that the entry file of the program is / cmd/registry/main.go,main function with only one sentence:
In fact, command binding has already been done when RootCmd is loaded, and the corresponding implementation of the subcommand serve is / registry/registry.go L 30. The main contents of the call are:
1. Read configuration file
two。 Pass the configuration parameter to the NewRegistry () function to instantiate a registry object (although the word object is not appropriate in the go language, the analogy is easier to understand)
3. Registry enters the port listening state and starts up.
The structure of the Registry object is defined in / registry/registry.go L68. Registry structure declares three members, as shown in figure 5, with configuration parameters, app, a http Server, and obviously, the most important member is app.
Fig. 5 Registry structure
The definition of App structure is / registry/handlers/app.go L54, and the members are long, mainly as follows:
1. Driver indicates back-end storage, which can be used for read / write / query and other operations through driver.
2. Router contains http routing rules to distribute different requests to different handler
3. Registry's main app backend
4. AccessController access Controller
The NewApp () function initializes the App instance and is implemented in / registry/handlers/app.go L91. The general flow of this function is as follows:
1. Declare an instance of app
two。 Bind web handler to an app instance
3. Initialize the back-end storage driver for app
4. Initialize the key for app
5. Configure redis caching for app
6. Initialize the backend storage redirection function of app
7. Initialize the backend registry of app according to the parameters
8. Returns the app instance
At this point, the call to NewRegistry () of / registry/registry.go also ends, returns the registry instance, and calls ListenAndServe () of registry to enter the listening state until the end of registry.
At this point, the study of "what is the overall architecture and startup process of Docker registryV2" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.