Container image sharing method, device, server, equipment and medium
By mounting remote mirror data locally and cache and share container images on the mirror cache server, the problems of untimely container startup, wasted space resources and system pressure are solved, and the rapid startup of containers and efficient utilization of resources are achieved.
Patent Information
- Application Number
- CN202110057434.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-15
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-01-15
AI Technical Summary
In the prior art, the pull time of container images is long, resulting in the container being started in time; at the same time, saving the same image on multiple computer devices is wasting space resources; and when starting the container in batches, the image warehouse and the image cache server will be affected. Due to greater pressure, network bottlenecks may occur.
Improve image acquisition speed by mounting remote mirror data locally and replacing the pulling image with mount. The mirror cache server caches container images in the mirror repository and generates a shared directory, allowing clients to mount the shared directory to a local mount point, thereby sharing the cached container images in the mirror cache server.
It realizes rapid startup of containers, saves disk space of computer equipment, reduces access pressure to mirror warehouses and mirror cache servers, and avoids network bottlenecks.
Smart Images

Figure CN112799780B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a container image sharing method, apparatus, server, device, and medium. Background Art
[0002] Containers are a lightweight process isolation technology that provides a resource-independent runtime environment for application software and its dependent components. Each container has its own independent file system, central processing unit (CPU), and memory resources, ensuring the independence of processes within the container from those outside it. Containers offer advantages such as easy deployment, fast startup, low resource consumption, good isolation, and high performance.
[0003] The file system of a running container typically consists of two parts: a read-only layer at the bottom layer and a read-write layer at the top layer. The contents of the read-only layer are immutable and can be shared by multiple containers. The read-write layer stores data written during container operation, and each container has its own independent read-write layer. The data in the container's read-only layer is also called an image. An image contains all the libraries, executable files, configuration files, and other dependencies that the container relies on to start and run. To improve image utilization, multiple containers can share images.
[0004] On a single computer, multiple containers using the same image can share a single image. Sharing container images can bring many benefits, such as saving time, disk space, and network bandwidth.
[0005] In the related art, when a container needs to be started, the container image is first pulled from the image repository. After the container image is pulled, the container can be started. Because pulling the container image takes a long time, the container cannot be started promptly and quickly when it is needed.
[0006] In addition, since multiple containers on the same computer device can share an image, it is necessary to save the same image on multiple computer devices, which wastes space resources on the computer devices.
[0007] In addition, when starting containers in batches, pulling container images from the image repository at the same time will put a lot of pressure on the image repository, and multiple computer devices may encounter network bottlenecks when pulling images at the same time. Summary of the Invention
[0008] The embodiments of the present application provide a container image sharing method, apparatus, server, device, and medium, which can solve the technical problems of not being able to start containers in a timely and rapid manner, wasting space resources on computer devices, and simultaneously pulling images of various containers from an image repository, which causes considerable pressure on the image repository and creates network bottlenecks.
[0009] In a first aspect, an embodiment of the present application provides a container image sharing method, applied to a client, the method comprising:
[0010] Obtain a path to a local mount point, where a shared directory in an image cache server is mounted on the local mount point, the shared directory includes a subdirectory of a container image cached in the image cache server, and the container image is stored in the subdirectory of the container image;
[0011] Determine the path of the target image according to the path of the local mount point and the shared directory, where the target image is the image of the target container to be started;
[0012] The target image cached in the image cache server is shared according to the path of the target image.
[0013] In a second aspect, an embodiment of the present application provides a container image sharing method, which is applied to an image cache server, and the method includes:
[0014] Cache container images in the image repository;
[0015] A shared directory is generated based on the container image, wherein the shared directory includes a subdirectory of the container image, and the container image is stored in the subdirectory of the container image, so that a client of each computer device mounts the shared directory to a local mount point, determines the path of the target image based on the path of the local mount point and the shared directory, and shares the target image based on the path of the target image.
[0016] In a third aspect, an embodiment of the present application provides a container image sharing device, which is applied to a client, and the device includes:
[0017] A first acquisition module is configured to acquire a path to a local mount point, where the local mount point is mounted with a shared directory in an image cache server, the shared directory includes a subdirectory of a container image cached in the image cache server, and the container image is stored in the subdirectory of the container image;
[0018] A determination module, configured to determine a path of a target image based on the path of the local mount point and the shared directory, where the target image is the image of the target container to be started;
[0019] A sharing module is used to share the target image cached in the image cache server according to the path of the target image.
[0020] In a fourth aspect, an embodiment of the present application provides a container image sharing device, which is applied to an image cache server, and the device includes:
[0021] Cache module, used to cache container images in the image repository;
[0022] A directory generation module is configured to generate a shared directory based on the container image, wherein the shared directory includes a subdirectory of the container image, and the container image is stored in the subdirectory of the container image, so that a client of each computer device mounts the shared directory to a local mount point, determines a path to a target image based on a path to the local mount point and the shared directory, and shares the target image based on the path to the target image.
[0023] In a fifth aspect, an embodiment of the present application provides a computer device, comprising: a processor and a memory storing computer program instructions, wherein the processor implements the container image sharing method of the first aspect when executing the computer program instructions.
[0024] In a sixth aspect, an embodiment of the present application provides an image cache server, the image cache server comprising: a processor and a memory storing computer program instructions;
[0025] When the processor executes the computer program instructions, the container image sharing method of the second aspect is implemented.
[0026] In a seventh aspect, an embodiment of the present application provides a computer storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the container image sharing method of the first aspect or the container image sharing method of the second aspect is implemented.
[0027] The container image sharing method, device, server, equipment and medium of the embodiment of the present application, the image cache server has cached the container image and a shared directory including a subdirectory of the container image, the container image is stored under the subdirectory, and the shared directory has been mounted to the local mount point of the client. Based on this, for the target container to be started, the client determines the path of the target container image (i.e., the target image) according to the shared directory and the path of the local mount point, and then shares the target image cached in the image cache server according to the path of the target image. First, since the path of the target image is determined, it is equivalent to obtaining the target image. Therefore, after determining the path of the target image, the target container can be started, and there is no need to pull the target image first and then start the target container, so that the target container can be started in time and quickly, which improves the startup speed of the target container. Secondly, since the container image cached in the image cache server can be shared by the client, there is no need to save the same container image on each computer device separately, so that the local disk space of the computer device is not occupied, saving more space resources. Third, during the process of starting and running the target container, when the target container's image is needed, the target container's image is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when batches of containers are started. Furthermore, this also prevents significant access pressure on the image cache server at the moment of batch container startup, avoiding network bottlenecks. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0029] Figure 1 This is a framework diagram of an embodiment of a system for implementing a container image sharing method provided by the present application.
[0030] Figure 2 This is a timing diagram of an embodiment of a container image sharing method provided by the present application.
[0031] Figure 3 This is a timing diagram of another embodiment of a container image sharing method provided by the present application.
[0032] Figure 4 This is a timing diagram of another embodiment of a container image sharing method provided by the present application.
[0033] Figure 5 This is a flowchart of an embodiment of a container image sharing method for a client provided by the present application.
[0034] Figure 6 This is a flow chart of an embodiment of a container image sharing method for an image cache server provided by the present application.
[0035] Figure 7 This is a structural diagram of an embodiment of a container image sharing device for a client provided by the present application.
[0036] Figure 8 This is a structural diagram of an embodiment of a container image sharing device for an image cache server provided by the present application.
[0037] Figure 9 A hardware structure diagram of an embodiment of the electronic device provided by the present application is shown. DETAILED DESCRIPTION
[0038] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is merely to provide a better understanding of the present application by illustrating the examples of the present application.
[0039] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0040] In related technologies, when a container needs to be started, the container image is first pulled from the image repository. After the container image is pulled, the container can be started. Before pulling the container image from the image repository, if it is determined that the required image is already locally, the image pulling process can be skipped, and the image is considered ready, and the container can be started directly.
[0041] Since the data size of container images is generally large, for example, container images range from tens of megabytes to hundreds of megabytes, it takes a long time to pull the container image, and as a result, the container cannot be started in a timely and fast manner when it needs to be started.
[0042] In addition, multiple containers using the same image can share a single image, but multiple containers on the same computer can share an image. However, in reality, different containers of the same application are deployed on different computers. Therefore, the same image needs to be stored on multiple computers, wasting space resources on the computer.
[0043] In addition, when starting containers in batches, it is necessary to pull the images of each container from the image repository at the same time, which will put a lot of pressure on the image repository, and multiple computer devices may encounter network bottlenecks when pulling images at the same time.
[0044] To address the aforementioned technical issues, how can we improve image pull speed and fully leverage the advantages of fast container startup? We came up with the idea of directly mounting remote image data locally. This significantly improves speed by replacing image pull with mounting. Furthermore, the container file system's Copy on Write (CoW) technology and Linux file cache mechanisms ensure that storing images remotely does not significantly degrade performance.
[0045] Based on the above concept, this application provides a container image sharing method. Figure 1 This is a framework diagram of an embodiment of a system for implementing a container image sharing method provided by the present application.
[0046] like Figure 1 As shown, the image cache server 102 pulls the container image from the image repository 104 and caches the container image, and generates a shared directory based on the cached container image. The shared directory includes a subdirectory of the cached container image, and the container image is stored in the subdirectory.
[0047] Then, the client on the computer device 106 (such as a host) can mount the shared directory to the local mount point according to the image cache configuration information. When it is necessary to start the target container on the computer device 106, the path of the local mount point is obtained, and the path of the target image is determined based on the path of the local mount point and the shared directory. Then, based on the path of the target image, the target image cached in the shared image cache server is used to achieve normal operation of the container on the computer device 106.
[0048] It should be noted that the client can be a container storage driver, similar to Overlay2 or Advanced Multi-Layered Unification Filesystem (AUFS). AUFS is a file system that merges multiple folders by mounting.
[0049] based on Figure 1 A system for implementing a container image sharing method is shown, and the container image sharing method provided by this application is described below.
[0050] Figure 2 This is a timing diagram of an embodiment of a container image sharing method provided by this application. Figure 2 As shown, container image sharing methods include:
[0051] S202: The image cache server caches the container image in the image repository. Specifically, the image cache server may pull commonly used container images from the image repository and cache the pulled container images.
[0052] S204: The image cache server generates a shared directory based on the container image. The shared directory includes a subdirectory of the cached container image. The container image is stored in the subdirectory of the container image.
[0053] In S204, the image cache server may start the Network File System (NFS) service and, during the NFS service startup process, generate a shared directory based on the cached container image. The shared directory may be an NFS shared directory. This facilitates the client to mount the shared directory to a local mount point via the NFS protocol.
[0054] The shared directory may include first-level subdirectories, and cached container images are stored in each level of subdirectories.
[0055] Alternatively, the shared directory may include multiple subdirectories, with the container image stored in the last subdirectory of the subdirectory. For example, the shared directory may include <library> / <name> / <tag>Third-level subdirectory.
[0056] After S204, the container image sharing method further includes:
[0057] S206: The client may mount the shared directory to a local mount point.
[0058] It should be noted that mounting refers to the process of making computer files and directories on a storage device (such as a hard disk, CD-ROM, or shared resource) accessible to users through the computer's file system. In the embodiment of the present application, mounting is the process of making a shared directory on the image cache server accessible to a computer device.
[0059] In S206, the client may mount the shared directory to the local mount point based on the image cache configuration information. The image cache configuration information is configuration information of the image cache server. The configuration information of the image cache server may include the Internet Protocol (IP) address and path of the network interconnection between the image cache servers. The image cache configuration information may be pre-configured in the client's configuration file.
[0060] In some embodiments, the client may mount the shared directory to a local mount point via the NFS protocol according to the image cache configuration information.
[0061] In some embodiments, during the client startup process, the client may mount the shared directory to the local mount point according to the image cache configuration information.
[0062] That is, when the client starts, the shared directory is mounted to the local mount point to facilitate subsequent access to the container images in the shared directory. For example, during the client startup process, the shared directory is mounted to the local mount point via the NFS protocol. This allows the subdirectories of each container image on the shared directory to be mounted to the local mount point using a single NFS channel, preventing the creation of an NFS connection for each container image and reducing the impact on the image cache server's service capabilities.
[0063] After S206, when any target container needs to be started, the container image sharing method includes:
[0064] S208, the client obtains the path of the local mount point;
[0065] S210: The client determines the path of the target image based on the path of the local mount point and the shared directory. The target image is the image of the target container to be started.
[0066] S212: The client shares the target image cached in the image cache server according to the path of the target image.
[0067] In the embodiment of the present application, first, since the path of the target image is determined, it is equivalent to obtaining the target image. Therefore, the target container can be started after the path of the target image is determined. There is no need to pull the target image first and then start the target container. Therefore, the target container can be started in a timely and fast manner, thereby improving the startup speed of the target container.
[0068] Secondly, since the container image cached in the image cache server can be shared through the client, there is no need to save the same container image on each computer device separately. This does not occupy the local disk space of the computer device, saving more space resources.
[0069] Third, during the process of starting and running the target container, when the target container's image is needed, it is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when starting a batch of containers. Furthermore, it also prevents significant access pressure on the image cache server during the instant of container batch startup, avoiding network bottlenecks.
[0070] In one or more embodiments of the present application, S210 may include:
[0071] The client sends a request to the image cache server for the target image.
[0072] The image cache server receives the acquisition request sent by the client;
[0073] The image cache server obtains the relative path (relative-path) based on the acquisition request. The relative path is the path from the local mount point to the subdirectory of the target image in the shared directory;
[0074] The mirror cache server sends a response including the relative path to the client of the computer device;
[0075] The client receives a response from the image cache server, which includes the relative path.
[0076] The client concatenates the path of the local mount point and the relative path to obtain the path of the target image. Specifically, the client can concatenate the relative path to the path of the local mount point to obtain the path of the target image.
[0077] In an embodiment of the present application, when a target container needs to be started, the client sends a request to the image cache server to obtain the target image. After the client sends the request to the image cache server, it can receive a relative path returned by the image cache server. Since the relative path is the path from the local mount point to the subdirectory of the target image in the shared directory, the relative path is concatenated with the path of the local mount point to obtain the path of the target image, which is equivalent to obtaining the target image.
[0078] In one or more embodiments of the present application, the image cache server obtains the relative path according to the acquisition request, which may specifically include:
[0079] The image cache server determines whether the target image is cached in the image cache server according to the identification information of the target image in the acquisition request;
[0080] If the target image has been cached in the image cache server, the image cache server obtains the relative path according to the identification information;
[0081] If the target image is not cached in the image cache server, the image cache server pulls the target image from the container image repository to the image cache server and obtains the relative path based on the identification information.
[0082] Among them, the identification information of the target image may include image repository information (repository) and tag (tag). According to the identification information, a container image matching the identification information can be obtained from the container images cached by the image cache server. The container image is the above-mentioned target image, and then the relative path of the container image is obtained.
[0083] In the embodiment of the present application, if the target image is not cached in the image cache server, the required target image can be pulled from the container image repository. Therefore, the image cache server does not need to cache all container images, but only commonly used container images. Container images can be dynamically pulled from the container image repository on demand, making the embodiment of the present application more flexible in implementation.
[0084] In one or more embodiments of the present application, the acquisition request may be a HyperText Transfer Protocol (HTTP) request, and the image cache server may start the HTTP service in advance so that it can subsequently receive an HTTP request sent from the client based on HTTP.
[0085] The following combination Figure 3 The container image sharing method of the embodiment of the present application is described. Figure 3 As shown, the container image sharing method may include:
[0086] S302, the image cache server caches the container image in the image repository;
[0087] S304, the image cache server starts the HTTP service and the NFS service. During the process of starting the NFS service, a shared directory is generated based on the container image cached in the image cache server. The shared directory includes a subdirectory of the cached container image, and the container image is stored in the subdirectory.
[0088] Among them, the HTTP channel corresponding to the HTTP service can process HTTP requests, such as control plane login / pull / push / logout requests, and the NFS channel corresponding to the NFS service can provide data plane image mounting services.
[0089] S302 and S304 are the initialization process of the image cache server. After S302 and S304, the container image sharing method further includes:
[0090] S306: The client mounts the remote shared directory to the local mount point through the NFS protocol according to the configuration information in the configuration file.
[0091] S306 is the client initialization process. At this point, the image cache server and client initialization have been completed. After this, the container image can be shared. After S306, the container image sharing method also includes:
[0092] S308: When the target container needs to be started, the client sends a request to the image cache server. The request may be an HTTP request for pulling an image. The request includes the image repository information and tag of the target image. The target image is the image of the target container.
[0093] S310: After receiving the acquisition request, the image cache server determines whether the target image is already cached in the image cache server based on the image repository information and the tag. If the target image is already cached in the image cache server, S312 is executed. If the target image is not cached in the image cache server, the target image is pulled from the image repository and S312 is then executed.
[0094] S312: The image cache server reads metadata of the target image based on the image repository information and tag. The metadata includes a relative path, which is the path from the local mount point to the subdirectory of the target image in the shared directory.
[0095] S314: The image cache server sends a response including the relative path to the client. The response may be an HTTP response. At this point, the HTTP session ends.
[0096] S316: After receiving the response including the relative path, the client obtains the path of the local mount point. It should be noted that in the embodiment of the present application, the path of the local mount point is obtained after the client receives the response. Of course, the path of the local mount point can also be obtained before sending the obtain request. The order of executing these two steps, obtaining the path of the local mount point and sending the obtain request, is not limited.
[0097] S318, concatenate the path of the local mount point and the relative path to obtain the path of the target image. For example, the path of the target image is <mountpoint> / <relative-path> , <mountpoint>Indicates the path of the local mount point, <relative-path>Indicates a relative path;
[0098] S320: The client shares the target image cached in the image cache server according to the path of the target image.
[0099] In one or more embodiments of the present application, the shared directory includes multiple levels of subdirectories, and the container image is stored in the lowest level subdirectory of the multiple levels of subdirectories. S210 may include:
[0100] The client concatenates the path of the local mount point and the multi-level subdirectories of the target image in the shared directory to obtain the path of the target image.
[0101] In this way, the process of determining the path of the target image is simplified, making the process of determining the path of the target image even simpler.
[0102] The following combination Figure 4 The container image sharing method of the embodiment of the present application is described. Figure 4 As shown, the container image sharing method may include:
[0103] S402, the image cache server caches the container image in the image repository;
[0104] S404, the image cache server starts the NFS service. During the process of starting the NFS service, a shared directory is generated based on the container image cached in the image cache server. The shared directory includes multiple subdirectories of the cached container image, and the container image is stored in the last subdirectory. For example, the shared directory includes <library> / <name> / <tag>Third-level subdirectory.
[0105] S402 and S404 are the initialization process of the image cache server. After S402 and S404, the container image sharing method further includes:
[0106] S406: The client mounts the remote shared directory to the local mount point via the NFS protocol according to the configuration information in the configuration file.
[0107] S406 is the client initialization process. At this point, the initialization of the image cache server and the client has been completed. After this, in order to achieve the sharing of container images, the container image sharing method also includes:
[0108] S408, the client obtains the path of the local mount point;
[0109] S410, the client concatenates the path of the local mount point and the multi-level subdirectories of the target image in the shared directory to obtain the path of the target image. For example, the path of the target image is <mountpoint> / <library> / <name> / <tag> , <mountpoint>Indicates the path of the local mount point, <library> / <name> / <tag>Represents the multi-level subdirectories of the target image in the shared directory;
[0110] S412: The client shares the target image cached in the image cache server according to the path of the target image.
[0111] Based on the above container image sharing method, this application provides a container image sharing method for a client. Figure 5 This is a flow chart of an embodiment of a container image sharing method for a client provided by this application. The container image sharing method is the container image sharing method of the first aspect, such as Figure 5 As shown, the container image sharing method 500 includes:
[0112] S502: Obtain a path to a local mount point. The local mount point is mounted with a shared directory in the image cache server. The shared directory includes a subdirectory of the container image cached in the image cache server. The container image is stored in the subdirectory of the container image.
[0113] S504: Determine the path of the target image based on the path of the local mount point and the shared directory. The target image is the image of the target container to be started.
[0114] S506: Sharing the target image cached in the image cache server according to the path of the target image.
[0115] In the embodiment of the present application, first, since the path of the target image is determined, it is equivalent to obtaining the target image. Therefore, the target container can be started after the path of the target image is determined. There is no need to pull the target image first and then start the target container. Therefore, the target container can be started in a timely and fast manner, thereby improving the startup speed of the target container.
[0116] Secondly, since the container image cached in the image cache server can be shared through the client, there is no need to save the same container image on each computer device separately. This does not occupy the local disk space of the computer device, saving more space resources.
[0117] Third, during the process of starting and running the target container, when the target container's image is needed, it is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when starting a batch of containers. Furthermore, it also prevents significant access pressure on the image cache server during the instant of container batch startup, avoiding network bottlenecks.
[0118] In one or more embodiments of the present application, S504 may include:
[0119] Send a request to the image cache server to obtain the target image. The request is used to enable the image cache server to obtain the relative path, which is the path from the local mount point to the subdirectory of the target image in the shared directory.
[0120] Receive the response from the image cache server, which includes the relative path;
[0121] Concatenate the local mount point path and the relative path to obtain the target image path.
[0122] In one or more embodiments of the present application, the shared directory includes multiple levels of subdirectories, and the container image is stored in the lowest level subdirectory of the multiple levels of subdirectories; S504 may include:
[0123] Concatenate the path of the local mount point and the multi-level subdirectories of the target image in the shared directory to obtain the path of the target image.
[0124] In the embodiment of the present application, the shared directory includes multiple sub-directories, so that the target image can be directly located in the shared directory according to the identification information of the target image. <library> / <name> / <tag>In this case, you can directly locate the target image in the shared directory based on its library, name, and tag. This makes it easier to read the target image.
[0125] In one or more embodiments of the present application, before obtaining the path of the local mount point, the container image sharing method 500 may further include:
[0126] Mount the shared directory to the local mount point based on the image cache configuration information.
[0127] In an embodiment of the present application, the shared directory is mounted to a local mount point so that the path of the target image can be determined based on the shared directory.
[0128] In one or more embodiments of the present application, mounting a shared directory to a local mount point according to the image cache configuration information may include:
[0129] During client startup, the shared directory is mounted to the local mount point according to the image cache configuration information.
[0130] When the client starts, the shared directory is mounted to the local mount point to facilitate subsequent access to the container images in the shared directory. For example, during the client startup process, the shared directory is mounted to the local mount point via the NFS protocol. This allows the subdirectories of each container image in the shared directory to be mounted to the local mount point using a single NFS channel, preventing the creation of an NFS connection for each container image and reducing the impact on the image cache server's service capabilities.
[0131] In one or more embodiments of the present application, mounting a shared directory to a local mount point according to the image cache configuration information may include:
[0132] Mount the shared directory to the local mount point using the network file system protocol based on the image cache configuration information.
[0133] This application provides a container image sharing method for an image cache server. Figure 6 This is a flow chart of an embodiment of a container image sharing method for an image cache server provided by the present application. The container image sharing method is a container image sharing method of the second aspect, such as Figure 6 As shown, the container image sharing method 600 includes:
[0134] S602, cache the container image in the image repository;
[0135] S604: Generate a shared directory based on the container image, where the shared directory includes a subdirectory of the container image. The container image is stored in the subdirectory of the container image, so that the client of each computer device mounts the shared directory to a local mount point, determines the path of the target image based on the path of the local mount point and the shared directory, and shares the target image based on the path of the target image.
[0136] In an embodiment of the present application, the image cache server generates a shared directory, allowing the client of each computer device to mount the shared directory to a local mount point and then determine the path of the target image. Since the client has determined the path of the target image, it is equivalent to obtaining the target image. Therefore, after the client determines the path of the target image, it can start the target container, without having to first pull the target image and then start the target container. This allows the target container to be started promptly and quickly, improving the startup speed of the target container.
[0137] Secondly, since the container image cached in the image cache server can be shared through the client, there is no need to save the same container image on each computer device separately. This does not occupy the local disk space of the computer device, saving more space resources.
[0138] Third, during the process of starting and running the target container, when the target container's image is needed, it is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when starting a batch of containers. Furthermore, it also prevents significant access pressure on the image cache server during the instant of container batch startup, avoiding network bottlenecks.
[0139] In one or more embodiments of the present application, after S604, the container image sharing method 600 may further include:
[0140] Receiving a request sent by a client of a computer device, where the request is used to request to obtain a target image;
[0141] Get the relative path based on the request. The relative path is the path from the local mount point to the subdirectory of the target image in the shared directory.
[0142] The response including the relative path is sent to the client of the computer device, so that the client of the computer device concatenates the path of the local mount point and the relative path to obtain the path of the target image.
[0143] In one or more embodiments of the present application, obtaining a relative path according to a request may include:
[0144] Determine whether the target image is cached in the image cache server according to the identification information of the target image in the acquisition request;
[0145] If the target image is already cached in the image cache server, the relative path is obtained according to the identification information;
[0146] If the target image is not cached in the image cache server, the target image is pulled from the container image repository to the image cache server, and the relative path is obtained according to the identification information.
[0147] In the embodiment of the present application, if the target image is not cached in the image cache server, the image cache server can pull the required target image from the container image repository. Therefore, the image cache server does not need to cache all container images, but only commonly used container images. Container images can be dynamically pulled from the container image repository on demand, making the embodiment of the present application more flexible in implementation.
[0148] In one or more embodiments of the present application, the acquisition request is a Hypertext Transfer Protocol request. Before receiving the acquisition request sent by the computer device, the container image sharing method 600 may further include:
[0149] Start the Hypertext Transfer Protocol service, which is used to receive Hypertext Transfer Protocol requests.
[0150] In the embodiment of the present application, the hypertext transfer protocol service is started so that an HTTP request sent from a client can be received based on HTTP.
[0151] In one or more embodiments of the present application, the shared directory may include multiple levels of subdirectories, and the container image is stored in the last level subdirectory of the multiple levels of subdirectories.
[0152] In the embodiment of the present application, the shared directory includes multiple sub-directories, so that the target image can be directly located in the shared directory according to the identification information of the target image. <library> / <name> / <tag>In this case, you can directly locate the target image in the shared directory based on its library, name, and tag. This makes it easier to read the target image.
[0153] In one or more embodiments of the present application, generating a shared directory based on a container image may include:
[0154] Start the network file system service and generate a shared directory based on the container image during the process of starting the network file system service.
[0155] Corresponding to the container image sharing method for a client provided in this application, this application provides a container image sharing device for a client, Figure 7 This is a structural diagram of an embodiment of a container image sharing device for a client provided by this application. Figure 7 As shown, the container image sharing device 700 includes:
[0156] A first acquisition module 702 is configured to acquire a path to a local mount point, where a shared directory in the image cache server is mounted on the local mount point, the shared directory including a subdirectory of the container image cached in the image cache server, and the container image is stored in the subdirectory of the container image;
[0157] Determination module 704, used to determine the path of the target image based on the path of the local mount point and the shared directory, where the target image is the image of the target container to be started;
[0158] The sharing module 706 is configured to share the target image cached in the image cache server according to the path of the target image.
[0159] In the embodiment of the present application, first, since the path of the target image is determined, it is equivalent to obtaining the target image. Therefore, the target container can be started after the path of the target image is determined. There is no need to pull the target image first and then start the target container. Therefore, the target container can be started in a timely and fast manner, thereby improving the startup speed of the target container.
[0160] Secondly, since the container image cached in the image cache server can be shared through the client, there is no need to save the same container image on each computer device separately. This does not occupy the local disk space of the computer device, saving more space resources.
[0161] Third, during the process of starting and running the target container, when the target container's image is needed, it is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when starting a batch of containers. Furthermore, it also prevents significant access pressure on the image cache server during the instant of container batch startup, avoiding network bottlenecks.
[0162] In one or more embodiments of the present application, the determination module 704 may include:
[0163] A sending unit, configured to send an acquisition request for a target image to an image cache server, wherein the acquisition request is used to enable the image cache server to obtain a relative path, where the relative path is a path from a local mount point to a subdirectory of the target image in a shared directory;
[0164] A receiving unit, configured to receive a response sent by the image cache server, wherein the response includes a relative path;
[0165] The splicing unit is used to splice the path of the local mount point and the relative path to obtain the path of the target image.
[0166] In one or more embodiments of the present application, the shared directory includes multiple levels of subdirectories, and the container image is stored in the lowest level subdirectory of the multiple levels of subdirectories; the determination module 704 can be specifically used to:
[0167] Concatenate the path of the local mount point and the multi-level subdirectories of the target image in the shared directory to obtain the path of the target image.
[0168] In the embodiment of the present application, the shared directory includes multiple sub-directories, so that the target image can be directly located in the shared directory according to the identification information of the target image. <library> / <name> / <tag>In this case, you can directly locate the target image in the shared directory based on its library, name, and tag. This makes it easier to read the target image.
[0169] In one or more embodiments of the present application, the container image sharing apparatus 700 may further include:
[0170] The mount module is used to mount the shared directory to the local mount point according to the image cache configuration information.
[0171] In one or more embodiments of the present application, the mounting module may be specifically used to:
[0172] During client startup, the shared directory is mounted to the local mount point according to the image cache configuration information.
[0173] When the client starts, the shared directory is mounted to the local mount point to facilitate subsequent access to the container images in the shared directory. For example, during the client startup process, the shared directory is mounted to the local mount point via the NFS protocol. This allows the subdirectories of each container image in the shared directory to be mounted to the local mount point using a single NFS channel, preventing the creation of an NFS connection for each container image and reducing the impact on the image cache server's service capabilities.
[0174] In one or more embodiments of the present application, the mounting module may be specifically used to:
[0175] Mount the shared directory to the local mount point using the network file system protocol based on the image cache configuration information.
[0176] Corresponding to the container image sharing method for the image cache server provided in this application, this application provides a container image sharing device for the image cache server, Figure 8 This is a structural diagram of an embodiment of a container image sharing device for an image cache server provided by this application. Figure 8 As shown, the container image sharing device 800 includes:
[0177] Cache module 802, used to cache container images in the image repository;
[0178] The generation module 804 is used to generate a shared directory based on the container image, where the shared directory includes a subdirectory of the container image, and the container image is stored in the subdirectory of the container image, so that the client of each computer device mounts the shared directory to a local mount point, determines the path of the target image based on the path of the local mount point and the shared directory, and shares the target image based on the path of the target image.
[0179] In an embodiment of the present application, the image cache server generates a shared directory, allowing the client of each computer device to mount the shared directory to a local mount point and then determine the path of the target image. Since the client has determined the path of the target image, it is equivalent to obtaining the target image. Therefore, after the client determines the path of the target image, it can start the target container, without having to first pull the target image and then start the target container. This allows the target container to be started promptly and quickly, improving the startup speed of the target container.
[0180] Secondly, since the container image cached in the image cache server can be shared through the client, there is no need to save the same container image on each computer device separately. This does not occupy the local disk space of the computer device, saving more space resources.
[0181] Third, during the process of starting and running the target container, when the target container's image is needed, it is read from the image cache server based on the target image's path. This disperses the reading of the target container's image throughout the target container's lifecycle, rather than reading the entire target container image before startup. This reduces the instantaneous access pressure on the image repository when starting a batch of containers. Furthermore, it also prevents significant access pressure on the image cache server during the instant of container batch startup, avoiding network bottlenecks.
[0182] In one or more embodiments of the present application, the container image sharing apparatus 800 may further include:
[0183] A receiving module, configured to receive an acquisition request sent by a client of a computer device, wherein the acquisition request is used to request acquisition of a target image;
[0184] The second acquisition module is used to obtain a relative path according to the acquisition request, where the relative path is a path from the local mount point to the subdirectory of the target image in the shared directory;
[0185] The sending module is used to send a response including the relative path to a client of the computer device, so that the client of the computer device can splice the path of the local mount point and the relative path to obtain the path of the target image.
[0186] In one or more embodiments of the present application, the second acquisition module may include:
[0187] A determining unit, configured to determine whether the target image is cached in the image cache server according to identification information of the target image in the acquisition request;
[0188] The acquisition unit is used to acquire the relative path according to the identification information when the target image has been cached in the image cache server;
[0189] A pulling unit is used to pull the target image from the container image repository to the image cache server if the target image is not cached in the image cache server;
[0190] The acquisition unit is further configured to: after pulling the target image to the image cache server, acquire the relative path according to the identification information.
[0191] In the embodiment of the present application, if the target image is not cached in the image cache server, the image cache server can pull the required target image from the container image repository. Therefore, the image cache server does not need to cache all container images, but only commonly used container images. Container images can be dynamically pulled from the container image repository on demand, making the embodiment of the present application more flexible in implementation.
[0192] In one or more embodiments of the present application, the acquisition request is a Hypertext Transfer Protocol request, and the container image sharing apparatus 800 may further include:
[0193] The startup module is used to start the Hypertext Transfer Protocol service, and the Hypertext Transfer Protocol service is used to receive Hypertext Transfer Protocol requests.
[0194] In the embodiment of the present application, the hypertext transfer protocol service is started so that an HTTP request sent from a client can be received based on HTTP.
[0195] In one or more embodiments of the present application, the shared directory includes multiple levels of subdirectories, and the container image is stored in the last level subdirectory of the multiple levels of subdirectories.
[0196] In the embodiment of the present application, the shared directory includes multiple sub-directories, so that the target image can be directly located in the shared directory according to the identification information of the target image. <library> / <name> / <tag>In this case, you can directly locate the target image in the shared directory based on its library, name, and tag. This makes it easier to read the target image.
[0197] In one or more embodiments of the present application, the generating module 804 is specifically configured to:
[0198] Start the network file system service and generate a shared directory based on the container image during the process of starting the network file system service.
[0199] The present application also provides a computer device, comprising: a processor and a memory storing computer program instructions, wherein the processor implements the container image sharing method of the first aspect when executing the computer program instructions.
[0200] The present application also provides an image cache server, which includes: a processor and a memory storing computer program instructions. When the processor executes the computer program instructions, the container image sharing method of the second aspect is implemented.
[0201] Figure 9 A hardware structure diagram of an embodiment of the electronic device provided by the present application is shown.
[0202] The electronic device may be a computer device or a mirror cache server. The electronic device may include a processor 901 and a memory 902 storing computer program instructions.
[0203] Specifically, the processor 901 may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0204] The memory 902 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 902 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 902 may include removable or non-removable (or fixed) media. Where appropriate, the memory 902 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 902 is a non-volatile solid-state memory.
[0205] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.
[0206] The processor 901 implements the container image sharing method of the first aspect or the container image sharing method of the second aspect by reading and executing computer program instructions stored in the memory 902 .
[0207] In one example, the electronic device may further include a communication interface 903 and a bus 910. Figure 9 As shown, the processor 901 , the memory 902 , and the communication interface 903 are connected via a bus 910 and communicate with each other.
[0208] The communication interface 903 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0209] Bus 910 includes hardware, software or both, and the components of online data flow metering equipment are coupled to each other. For example, but not limitation, bus can include accelerated graphics port (AGP) or other graphics bus, enhanced industry standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industry standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 910 can include one or more buses. Although the present application embodiment describes and shows specific bus, the application considers any suitable bus or interconnection.
[0210] In addition, the present application also provides a computer storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the container image sharing method of the first aspect or the container image sharing method of the second aspect is implemented.
[0211] It should be understood that the present application is not limited to the specific configurations and processes described above and illustrated in the figures. For the sake of brevity, a detailed description of known methods is omitted here. In the above embodiments, several specific steps are described and illustrated as examples. However, the method process of the present application is not limited to the specific steps described and illustrated. Those skilled in the art can make various changes, modifications, and additions, or change the order of the steps after understanding the spirit of the present application.
[0212] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. The machine-readable medium can include a non-transient computer-readable storage medium, such as an electronic circuit, a semiconductor memory device, a ROM, a flash memory, an erasable ROM (EROM), a floppy disk, a CD-ROM, an optical disc, a hard disk, an optical fiber medium, and the machine-readable medium can also include a radio frequency (RF) link, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0213] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps. In other words, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0214] Aspects of the present disclosure have been described above with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit. It is also understood that each box in the block diagram and / or flowchart and the combination of the boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0215] The above is only a specific implementation method of the present application. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the scope of protection of the present application is not limited to this. Any technician familiar with this technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the scope of protection of this application.< / tag> < / name> < / library> < / tag> < / name> < / library> < / tag> < / name> < / library> < / tag> < / name> < / library> < / tag> < / name> < / library> < / mountpoint> < / tag> < / name> < / library> < / mountpoint> < / tag> < / name> < / library> < / mountpoint> < / relative-path> < / mountpoint> < / tag> < / name> < / library>
Claims
1. A container image sharing method, applied to a client, characterized in that: The method comprises: Obtain a path to a local mount point, where a shared directory in an image cache server is mounted on the local mount point, where the shared directory includes a subdirectory of a container image cached in the image cache server, where the container image is stored in the subdirectory of the container image; Determine the path of the target image according to the path of the local mount point and the shared directory, where the target image is the image of the target container to be started; Sharing the target image cached in the image cache server according to the path of the target image; Determining the path of the target image according to the path of the local mount point and the shared directory includes: Sending a request for obtaining the target image to the image cache server, wherein the request is used to enable the image cache server to obtain a relative path, where the relative path is a path from the local mount point to a subdirectory of the target image in the shared directory; Receiving a response sent by the image cache server, wherein the response includes the relative path; Concatenate the path of the local mount point and the relative path to obtain the path of the target image; The method further comprises: after determining the path of the target image, starting the target container; Before obtaining the path of the local mount point, the method further includes: mounting the shared directory to the local mount point according to the image cache configuration information.
2. The method according to claim 1, characterized in that The shared directory includes multiple levels of subdirectories, and the container image is stored in the lowest level subdirectory of the multiple levels of subdirectories; Determining the path of the target image according to the shared directory includes: The path of the local mount point and the multi-level subdirectories of the target image in the shared directory are concatenated to obtain the path of the target image.
3. The method according to claim 1, characterized in that Mounting the shared directory to the local mount point according to the image cache configuration information includes: During the startup of the client, the shared directory is mounted to the local mount point according to the image cache configuration information.
4. The method according to claim 1, characterized in that Mounting the shared directory to the local mount point according to the image cache configuration information includes: According to the image cache configuration information, the shared directory is mounted to the local mount point through a network file system protocol.
5. A container image sharing method, applied to an image cache server, characterized in that: The method comprises: Cache container images in the image repository; Generate a shared directory according to the container image, wherein the shared directory includes a subdirectory of the container image, and the container image is stored under the subdirectory of the container image, so that the client of each computer device mounts the shared directory to a local mount point according to the image cache configuration information, determines the path of the target image according to the path of the local mount point and the shared directory, starts the target container, and shares the target image according to the path of the target image; After generating a shared directory according to the container image, the method further includes: Receiving an acquisition request sent by a client of the computer device, wherein the acquisition request is used to request to acquire a target image; Acquire a relative path according to the acquisition request, where the relative path is a path from the local mount point to a subdirectory of the target image in the shared directory; A response including the relative path is sent to the client of the computer device, so that the client of the computer device concatenates the path of the local mount point and the relative path to obtain the path of the target image.
6. The method according to claim 5, characterized in that The obtaining of the relative path according to the obtaining request includes: Determining whether the target image is cached in the image cache server according to the identification information of the target image in the acquisition request; In a case where the target image has been cached in the image cache server, acquiring the relative path according to the identification information; In the case that the target image is not cached in the image cache server, the target image is pulled from the container image repository to the image cache server, and the relative path is obtained according to the identification information.
7. The method according to claim 5, characterized in that The acquisition request is a hypertext transfer protocol request, Before receiving the acquisition request sent by the computer device, the method further includes: A hypertext transfer protocol service is started, where the hypertext transfer protocol service is used to receive the hypertext transfer protocol request.
8. The method according to claim 5, characterized in that The shared directory includes multiple levels of subdirectories, and the container image is stored in the last level of the subdirectories.
9. The method according to any one of claims 5 to 8, characterized in that The step of generating a shared directory according to the container image includes: The network file system service is started, and in the process of starting the network file system service, the shared directory is generated according to the container image.
10. A container image sharing device, applied to a client, characterized in that: The device comprises: A first acquisition module is used to acquire a path of a local mount point, where the local mount point is mounted with a shared directory in an image cache server, where the shared directory includes a subdirectory of a container image cached in the image cache server, and where the container image is stored in the subdirectory of the container image; A determination module, configured to determine a path of a target image according to a path of the local mount point and the shared directory, wherein the target image is an image of a target container to be started; A sharing module, used for sharing the target image cached in the image cache server according to the path of the target image; The determination module comprises: A sending unit, configured to send a request for obtaining the target image to the image cache server, wherein the request is used to enable the image cache server to obtain a relative path, where the relative path is a path from the local mount point to a subdirectory of the target image in the shared directory; A receiving unit, configured to receive a response sent by the image cache server, wherein the response includes the relative path; A concatenation unit, configured to concatenate the path of the local mount point and the relative path to obtain the path of the target image; The device is also used to start the target container after determining the path of the target image; The mounting module is used to mount the shared directory to the local mounting point according to the image cache configuration information.
11. A container image sharing device, applied to an image cache server, characterized in that: The device comprises: The cache module is used to cache container images in the image repository; A directory generation module, configured to generate a shared directory according to the container image, wherein the shared directory includes a subdirectory of the container image, and the container image is stored under the subdirectory of the container image, so that a client of each computer device mounts the shared directory to a local mount point according to the image cache configuration information, determines a path of a target image according to a path of the local mount point and the shared directory, starts the target container, and shares the target image according to the path of the target image; The container image sharing device also includes: A receiving module, used for receiving an acquisition request sent by a client of the computer device, wherein the acquisition request is used for requesting to acquire a target image; A second acquisition module, configured to acquire a relative path according to the acquisition request, wherein the relative path is a path from the local mount point to a subdirectory of the target image in the shared directory; The sending module is used to send a response including the relative path to the client of the computer device, so that the client of the computer device concatenates the path of the local mount point and the relative path to obtain the path of the target image.
12. A computer device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the container image sharing method according to any one of claims 1 to 4 is implemented.
13. A mirror cache server, characterized in that: The image cache server includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the container image sharing method according to any one of claims 5 to 9 is implemented.
14. A computer storage medium, characterized in that: The computer storage medium stores computer program instructions, and when the computer program instructions are executed by the processor, the container image sharing method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Method and device for sharing container mirror image by physical machine, equipment and storage medium
CN110704162A