Container starting method and device, equipment, storage medium and program product

By obtaining the target description file and mirror layer identifier of the container image, and obtaining and using the target storage block to mount the container, the problem of long container startup time is solved, and efficient container startup and persistence is achieved.

CN119829203APending Publication Date: 2025-04-15MOORE THREADS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411877450.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

The creation and startup time of large container images is long, resulting in low container startup efficiency and cannot meet the requirements of efficient container startup.

Method used

By obtaining the target description file of the target image, obtaining the target storage block based on the image layer identification, and mounting the startup container through these storage blocks to avoid downloading the complete image.

Benefits of technology

Improve container startup efficiency, reduce startup time, and realize container persistence, meeting the needs of efficient container startup and persistence.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829203A_ABST
    Figure CN119829203A_ABST
Patent Text Reader

Abstract

The invention provides a container starting method and device, equipment, a storage medium and a program product. The method comprises the steps that a target description file of a target mirror image is acquired, the target description file indicates at least one mirror image layer of the target mirror image, and different mirror image layers correspond to different mirror image layer identifiers; based on the mirror image layer identifier of each mirror image layer in the target mirror image, obtaining a target storage block corresponding to a target mirror image layer in the target mirror image, different mirror image layer identifiers corresponding to different storage blocks, and the target storage block storing mirror image content of the target mirror image layer; and based on the target storage block, mounting and starting a container corresponding to the target mirror image. According to the method, the container starting efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a container startup method, device, equipment, storage medium and program product. Background Art

[0002] With the development of large models, the image size of containers has become larger and larger. When creating a container, it takes a lot of time to download the complete image, but only a small number of files in the image are actually used during the operation of the container, resulting in long container startup time and low efficiency.

[0003] In some solutions, the standard format image is first converted into an image format that supports file indexing, and then used with a container creation tool. This allows the user to create a container without downloading the entire image. Instead, the user only needs to download the files required for the current operation to accelerate the startup of the container. However, this solution can only achieve limited results in accelerating the startup of containers and cannot meet the requirements for efficient container startup. Summary of the invention

[0004] The present application provides a container startup method, device, equipment, storage medium and program product to solve the problem of low container startup efficiency.

[0005] In a first aspect, the present application provides a container startup method, comprising:

[0006] Obtain a target description file of a target image, where the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers;

[0007] Based on the image layer identifiers of each image layer in the target image, obtaining a target storage block corresponding to the target image layer in the target image, where different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer;

[0008] Based on the target storage block, a container corresponding to the target image is mounted and started.

[0009] In an implementable manner, at least one image layer in the target image has an arrangement order, and storage blocks corresponding to each image layer have a reference relationship based on the arrangement order; acquiring a target storage block corresponding to a target image layer in the target image based on an image layer identifier of each image layer in the target image includes:

[0010] The last image layer in the arrangement order is used as the target image layer;

[0011] A corresponding target storage block is obtained from a preset storage block set based on the image layer identifier of the target image layer, and the target storage block is used to reference storage blocks of other image layers in the target image except the target image layer based on the reference relationship.

[0012] In an implementable manner, at least one image layer in the target image has an arrangement order, and storage blocks corresponding to each image layer have a reference relationship based on the arrangement order; and mounting and starting a container corresponding to the target image based on the target storage block includes:

[0013] Mapping the target storage block to a target location to obtain a mount file at the target location;

[0014] The mount file at the target location is read to access the target storage block through the mount file, and the storage blocks of other image layers in the target image except the target image layer are referenced according to the reference relationship to start the container corresponding to the target image.

[0015] In an implementable manner, before obtaining the target description file of the target image, the method further includes:

[0016] For each image layer in the target image, create a corresponding initial storage block, where the name of the initial storage block is the image layer identifier of the corresponding image layer;

[0017] The image content in each image layer in the target image is copied into the corresponding initial storage block to obtain the storage block corresponding to each image layer.

[0018] In an implementable manner, after mounting and starting the container corresponding to the target image based on the target storage block, the method further includes:

[0019] When the container corresponding to the target image is running, a blank file is generated;

[0020] Based on the blank file, obtain a working image layer identifier corresponding to a working image layer in the working image, wherein the working image represents a working environment of a container corresponding to the target image at runtime, and the working image includes the working image layer;

[0021] The data generated when the container corresponding to the target image is running is used as the image content of the working image layer, and stored in a working storage block, where the working storage block is named as the working image layer identifier;

[0022] A working description file of the working image is generated based on the working image layer identifier and the target configuration file of the target image, and the working description file is used to locate the working storage block and the configuration file to generate a container corresponding to the working image.

[0023] In an implementable manner, the target description file indicates a target configuration file of the target image; and generating a working description file of the working image based on the working image layer identifier and the target configuration file of the target image includes:

[0024] Replacing the identifier in the target configuration file with the working image layer identifier to obtain a working configuration file;

[0025] Generate an initial description file based on a preset description file template;

[0026] The working image layer identifier is written into the image layer field in the initial description file, and the index relationship of the working configuration file is written into the configuration file field in the initial description file to obtain the working description file.

[0027] In an implementable manner, the target description file indicates an image layer file corresponding to each image layer in the target image; and obtaining a working image layer identifier corresponding to a working image layer in the working image based on the blank file includes:

[0028] Write a random field into the blank file, and use the blank file with the random field written into it as the working image layer file of the working image layer;

[0029] A working image layer identifier is generated based on the working image layer file.

[0030] In a second aspect, the present application provides a container startup device, including: a target description file acquisition module, used to acquire a target description file of a target image, wherein the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers;

[0031] A target storage block acquisition module is used to acquire a target storage block corresponding to a target image layer in the target image based on the image layer identifiers of each image layer in the target image, where different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer;

[0032] The container startup module is used to mount and start the container corresponding to the target image based on the target storage block.

[0033] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory; the memory is used to store instructions; the processor is used to execute the instructions in the memory, so that the electronic device executes the method described in the first aspect.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.

[0035] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.

[0036] The container startup method, apparatus, device, storage medium and program product provided by the present application store the image layer in the image in the corresponding storage block, and set the storage block to correspond to the image layer identifier. Therefore, when the container is started, the corresponding storage block is obtained through the image layer identifier, and the container can be mounted and started through the storage block, without downloading the complete image, which can improve the efficiency of container startup. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] Figure 1 This is an implementation scenario diagram shown for an exemplary embodiment;

[0039] Figure 2 A structural diagram of the preset configuration data shown in an exemplary embodiment;

[0040] Figure 3 A structural diagram of a container startup system is shown as an exemplary embodiment;

[0041] Figure 4 This is a structural diagram of a container starting device shown as an exemplary embodiment;

[0042] Figure 5 The present invention is a block diagram of an electronic device showing an exemplary embodiment.

[0043] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0044] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0045] First, the terms involved in this application are explained:

[0046] Containers: A form of operating system virtualization that can run everything from small microservices or software processes to large applications using a single container that contains all the necessary executables, binary code, libraries, and configuration files.

[0047] An image is a lightweight, independent executable software package that contains all the code, dependencies, and environment settings required to run an application. It is usually composed of multiple layers, each of which represents a step in the image building process. When the container is started, these layers are combined in a stacked manner to form the container's file system.

[0048] A complete image consists of the following parts:

[0049] An Index file that stores the manifest file indexes corresponding to different image / platform architectures in Json format (JavaScript Object Notation, a lightweight data exchange format).

[0050] A Manifest file that records the config and layer file indexes of the image in Json format.

[0051] A Config file that records configuration information such as container startup parameters and environment variables.

[0052] At least one Layer file. One Layer file corresponds to a layer in the image. Multiple Layer files are decompressed and superimposed together to form a file system.

[0053] Containerd is a container runtime platform that emphasizes simplicity, robustness, and portability. Containerd can manage the entire container lifecycle in the host, including image transmission and storage, container execution and monitoring, underlying storage and networking, etc.

[0054] Snapshotter is an important component of Containerd. It is responsible for managing the file system layer of the container and composing the image layer into the container file system so that the container can read and modify the file system efficiently.

[0055] Remote Snapshotter is a special type of snapshotter for Containerd, which allows containerd to use file system snapshots directly from remote storage without pulling the image layer from the container image registry to the local. This mechanism can significantly speed up the pull time of container images, especially when dealing with large images or in bandwidth-constrained environments.

[0056] Ceph RBD (Reliable Block Device, a subproject of Ceph) is a block device interface in the Ceph (an open source distributed storage system) storage system. It can be mounted and used like a traditional hard disk or disk partition. It is often used in cloud computing, virtualization environments, database storage and other scenarios to provide reliable and high-performance block storage services for applications.

[0057] With the development of large models, the size of container images has become larger and larger, resulting in a lot of time spent downloading the complete image when creating a container. However, only a small number of files in the image are used during the operation of the container, resulting in long container startup time and low efficiency. In addition, the content generated during the operation of the container will not be saved after the container exits. However, in the process of using the container for related business, it is generally hoped that the complete working environment of the container after the operation can be saved and reused at any time to avoid repeated configuration each time, that is, the container cannot be used persistently, which also leads to low efficiency of container use.

[0058] There are usually two ways to persist containers: one is to mount a persistent volume to the container directory when the container starts, write the content to be saved to the directory, and mount the volume to restore the environment when creating a new container. However, this method can only save the content of the mounted directory, and cannot save the changes made by the user to the operating system. The other method is to use client tools to save all the differences between the container and the image to a new image layer. This image layer and all the layers of the original image are combined into a new image and saved. This method can save all changes in the container, but if there are many changes, it will be time-consuming to make and upload the image.

[0059] In terms of accelerating container startup, some solutions first convert the standard format image into an image format that supports file indexing. When creating a container, there is no need to download the complete image with snapshot software. Only the files required for the current operation are downloaded to achieve the acceleration purpose. This solution can only achieve limited purpose of container image acceleration and cannot meet the needs of efficient container startup.

[0060] Based on this, a container startup method, device, equipment, storage medium and program product are proposed in this embodiment. The process stores the image layer in the container in the corresponding storage block, and sets the storage block to correspond to the image layer identifier. Therefore, when the container is started, the corresponding storage block is obtained through the image layer identifier in the container. The container can be mounted and started through the storage block without downloading the complete image, which can improve the efficiency of container startup. The data generated during the subsequent container operation is directly stored in the corresponding newly added storage block, thereby meeting the persistence requirements of the container.

[0061] The container startup method provided in this application can be implemented on any electronic device with data processing capabilities, or it can be a container startup system. It should be noted that the container startup system can be deployed separately on an electronic device in any environment (for example: deployed separately on an edge server in an edge environment), or it can be deployed entirely in a cloud environment, or it can be deployed in a distributed manner in different environments.

[0062] For example, the container startup system can be logically divided into multiple parts, each with different functions. The various parts in the container startup system can be deployed in any two or three of the electronic device (located on the user side, such as the client), the edge environment, and the cloud environment. The edge environment is an environment that includes a collection of edge electronic devices that are close to the electronic device. The edge electronic devices include: edge servers, edge stations with computing power, etc. The various parts of the container startup system deployed in different environments or devices work together to realize the functions of the data processing platform.

[0063] It should be understood that this application does not restrictively divide which parts of the container startup system are deployed in what specific environment. In actual application, it can be adaptively deployed according to the computing power of the electronic device, the resource usage of the edge environment and the cloud environment, or the specific application requirements.

[0064] like Figure 1 This is an implementation scenario diagram showing an exemplary embodiment. The container startup system corresponding to the implementation scenario includes a client 10 and a server 11. The client 10 and the server 11 are connected via network communication.

[0065] The execution subject of the method of the embodiment of the present application is the server 11, and the client 10 can receive a container startup request. The client 10 sends the container startup request to the server 11 through the network. The server 11 starts the container and can feed back the started container to the client 10 through the network. The client 10 has a graphic user interface, and the container can be displayed on the graphic user interface.

[0066] In some embodiments, after receiving a container startup request, the server 11 corresponds to a target image, obtains a target description file of the target image, the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers; based on the image layer identifiers of each image layer in the target image, obtains a target storage block corresponding to the target image layer in the target image, different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer; based on the target storage block, mounts and starts a container corresponding to the target image.

[0067] It is understandable that the container starting device can be arranged at Figure 1 In the server 11, but the example shown in this embodiment Figure 1 The implementation environment shown is only exemplary. In other embodiments, the container startup method can also be applied to other implementation environments, and the container startup device can also be set in other structures in other implementation environments, which is not specifically limited here.

[0068] In this embodiment, the client 10 is an electronic device on the user side, which can be a wired terminal with a visualization structure or a wireless terminal. In other embodiments, the terminal can be an electronic device with a visualization structure such as a mobile phone, a computer, a tablet, and a vehicle-mounted device.

[0069] The server 11 can be an edge environment and a cloud environment, such as a physical server, a server cluster, and a cloud server, etc., and no specific limitations are made here.

[0070] It is understandable that the container starting device can be arranged at Figure 1 In the server 11, but the example shown in this embodiment Figure 1 The implementation environment shown is only exemplary. In other embodiments, the container startup method can also be applied to other implementation environments, and the container startup device can also be set in other structures in other implementation environments, which is not specifically limited here.

[0071] Figure 2 is a flowchart of a container startup method shown in an exemplary embodiment, which is applied to Figure 1 The server 11 in Figure 2 As shown, the method includes steps S210 to S270, which are described in detail as follows:

[0072] Step S210: obtaining a target description file of a target image, where the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers.

[0073] In this embodiment, when a container needs to be started, an image corresponding to the container is searched, and a file corresponding to the image is used to start the container corresponding to the image.

[0074] It can be understood that an image corresponds to at least one image layer, and an image layer is called Layer. An image can obtain multiple containers. An image has a corresponding description file, which is the above-mentioned manifest file. The target description file indicates at least one image layer of the target image, and an image layer corresponds to an image layer identifier.

[0075] In this embodiment, the target image corresponding to the required container to be started is determined, and the target description file of the target image is obtained. It can be understood that the target description file of the target image is in the container image repository, and the container image repository stores description files, image layer files and configuration files of different images. The image layer file is the Layer file corresponding to the image layer, and the configuration file is the Config file of the image. The description file of the image stores the index of the Layer file corresponding to the image layer of the image and the Config file of the image.

[0076] Step S230: based on the image layer identifiers of each image layer in the target image, obtain the target storage block corresponding to the target image layer in the target image, different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer.

[0077] In this embodiment, after determining the target description file of the target image, the target description file of the target image and the image layer files and configuration files corresponding to the target description file are downloaded, but the corresponding storage blocks are indexed through the image layer identifiers of each image layer in the target image, and the container corresponding to the target image is hung through the storage blocks. In this way, the container can be started without downloading all files of the target image, thereby improving the efficiency of container startup.

[0078] In this embodiment, a preset storage block set is set, and there are storage blocks in the preset storage block set. The storage blocks can be regarded as Ceph RBDs, one storage block corresponds to one image layer, and the image content of the image layer is stored in the storage block, which can also be regarded as the storage block storing the content in the image layer file of the image layer.

[0079] For an image, there are a number of image layers, that is, a corresponding number of storage blocks are stored in a preset storage block set. The storage blocks corresponding to each image layer are named with an image layer identifier, and different image layer identifiers correspond to different storage blocks.

[0080] After obtaining the target description file, the image layer identifiers of each image layer in the target description file are traversed. Through the image layer identifier, a storage block named with the image layer identifier can be indexed in a preset storage block set, and subsequent container generation is performed through the content in the storage block.

[0081] In some embodiments, the target image layer may be an image layer corresponding to all image layer identifiers of the target image, or may be the last image layer in the target image.

[0082] In one embodiment, there is an arrangement order between at least one image layer in the target image, and there is a reference relationship between the image layers. The reference relationship is generally that the latter image layer in the arrangement order references the previous image layer. For example, if there are n image layers and there is an arrangement order between the n image layers, then in the arrangement order, the n image layer references the n-1 image layer, and the storage block stores the image layer file of the corresponding image layer. It can be understood that there is a reference relationship between the storage blocks corresponding to the image layers based on the arrangement order, and the storage block corresponding to the n-1 image layer references the storage block corresponding to the n-1 image layer.

[0083] Based on the reference relationship, it can be understood that as long as the image layer located at the last layer in the arrangement order is found, all the image layers in the target image can be determined through the reference relationship between the image layer and other image layers, that is, the storage block corresponding to the image layer located at the last layer in the arrangement order is found, and all the storage blocks corresponding to the target image can be determined through the reference relationship between the storage block and other storage blocks.

[0084] Therefore, in this embodiment, the image layer located at the last layer in the arrangement order is used as the target image layer; based on the image layer identifier of the target image layer, the corresponding target storage block is obtained in the preset storage block set, and the target storage block is used to reference the storage blocks of other image layers in the target image except the target image layer based on the reference relationship.

[0085] The target storage block is used to reference the storage blocks of other image layers except the target image layer in the target image based on the reference relationship. It can be regarded as that the target storage block references the storage block of the image layer before the target image layer in the arrangement order, and the storage block of the image layer before the target image layer in the arrangement order references the storage block of the image layer before the arrangement order, that is, the storage block corresponding to the n-1 image layer references the storage block corresponding to the n-2 image layer, until the storage block corresponding to the first image layer is referenced. In this way, the reference between the storage blocks corresponding to the target image is realized through the reference relationship and the target storage block.

[0086] In some embodiments, a method for generating a storage block is also proposed. For each image layer in the target image, a corresponding initial storage block is created, and the initial storage block is named the image layer identifier of the corresponding image layer; the image content in each image layer in the target image is copied into the corresponding initial storage block to obtain the storage block corresponding to each image layer.

[0087] The storage block is stored in a preset storage block set, and the storage block corresponding to the image layer identifier index can be used. It can be understood that the image content is the content in the Layer file corresponding to the image layer.

[0088] Step S250: Based on the target storage block, mount and start the container corresponding to the target image.

[0089] It can be understood that when the target image layer can be the image layer corresponding to all image layer identifiers of the target image, the storage blocks corresponding to each image layer in the target image are all target storage blocks. At this time, the target storage block can be copied, and the copied target storage block can be mapped to the target location, such as locally, and the target storage block copied from the target location can be used to mount the container corresponding to the target image.

[0090] It should be noted that when mounting the container corresponding to the target image, the corresponding target configuration file will be indexed according to the target description file, and the container will be mounted through the configuration file and the image content in the target storage block.

[0091] In some embodiments, the target image layer may also be the last image layer in the target image, and the target storage block is the last image layer. At this time, the target storage block may be mounted at the target location, so that a mount file of the target storage block exists at the target location. The mount file is read, and the mount file may access the target storage block, and reference the storage blocks of other image layers in the target image except the target image layer according to the reference relationship, and start the container corresponding to the target image.

[0092] In some embodiments, the target storage block is mapped to the target location to achieve mounting.

[0093] In some embodiments, the mount file has the files included in the target storage block, but there is no specific description data in the files in the target storage block, such as an empty file. In another embodiment, the target storage block has file 1 and file 2, file 1 has first description data, and file 2 has second description data. The mount file can determine the files in the target storage block. The mount file has file 1 and file 2, but file 1 and file 2 in the mount file do not have specific description data of files 1 and 2 in the target storage block.

[0094] When the container needs to be started, the mount file can be read to determine the data required by the file, and thus the data required by the container in the target storage block can be read through the mount file.

[0095] In some embodiments, the container may be started by accessing a mount file.

[0096] In some embodiments, container startup may only require part or all of the data in the target storage block. The target storage block can be accessed by mounting the file, and the required data can be copied to the target location to start the container. In other embodiments, container startup also requires part or all of the data in the storage blocks of other image layers except the target image layer. In this case, the target storage block can be accessed by mounting the file, and the storage blocks of other image layers except the target image layer in the target image can be referenced according to the reference relationship. The data required for starting the container in the target storage block and / or the storage blocks of other image layers except the target image layer in the target image can be copied to the target location, thereby starting the container.

[0097] Similarly, the container mounting process relies not only on the reference relationship, but also on the target configuration file corresponding to the target description file index.

[0098] When the target image layer can also be the last image layer in the target image, mounting the container only requires mapping the storage block corresponding to the last image layer to the target location, which greatly improves the speed of container startup. At the same time, before starting the container, there is no need to download the image layer from the image repository. Instead, the image content storage block is stored by mounting, which further speeds up the startup of the container.

[0099] In other embodiments, after the container is started, corresponding operations can be performed on the container. At this time, the working environment of the container will change, and the original target image cannot feedback or store the change. The changed working environment cannot be obtained by subsequently mounting the container through the target image. Therefore, in this embodiment, when the container is running, a new working image is generated. The working image can indicate the working environment of the container corresponding to the target image at runtime. Subsequently, the working image can be used to realize the mounting of the container with the changed working environment, thereby realizing the persistence of the container.

[0100] In some embodiments, when the container corresponding to the target image is running, a blank file is generated; based on the blank file, a working image layer identifier corresponding to the working image layer in the working image is obtained, the working image represents the working environment of the container corresponding to the target image at runtime, and the working image includes a working image layer; the data generated when the container corresponding to the target image is running is used as the image content of the working image layer, and stored in a working storage block, and the working storage block is named the working image layer identifier; based on the working image layer identifier and the configuration file of the target image, a working description file of the working image is generated, and the working description file is used to locate the working storage block and the configuration file to generate a container corresponding to the working image.

[0101] In some embodiments, the description file needs to index the image layer files and configuration files, such as the target description file indicates the image layer files corresponding to each image layer in the target image; and the container in this embodiment is a mounted target storage block, so that the data generated when the container is running can be stored as a new storage block in a preset storage block set. At this time, the image layer file of the working image does not need to store the data generated when the container is running, and the working image layer file of the working image can be determined through a blank file.

[0102] It can be understood that the data generated in the process of starting the container and closing the container are all stored in one storage block, corresponding to only one working image layer for the working image.

[0103] In this embodiment, a random field is written into a blank file, and the blank file into which the random field is written is used as a working image layer file of the working image layer, and a working image layer identifier is generated based on the working image layer file.

[0104] In order to allow the working storage block to be indexed by the working image layer identifier, the working storage block is named after the working image layer identifier.

[0105] In this embodiment, the random field can be a randomly generated string of characters, which is not specifically limited here. The working image layer identifier is generated based on the working image layer file, which can be a string of identifiers obtained by encrypting the working image layer file, etc., which is not specifically limited here.

[0106] In one embodiment, the target description file indicates the target configuration file of the target image; when mounting the container corresponding to the target image, the configuration file is required to configure the parameters of the container. Therefore, the description file of the working image should also contain an index of the corresponding working configuration file. Because the working image is processed on the container obtained from the target image, the configuration files of the working image and the target image should be basically the same. In this embodiment, the target configuration file can be processed accordingly to obtain the working configuration file.

[0107] In this embodiment, the identifier in the target configuration file is replaced with the working image layer identifier to obtain the working configuration file; an initial description file is generated based on a preset description file template; the working image layer identifier is written into the image layer field in the initial description file, and a reference relationship to the working configuration file is written into the configuration file field in the initial description file to obtain the working description file.

[0108] The identifier in the target configuration file can be the content in the diffs (an array used to store differences or changes) array of the target configuration file. The target configuration file is copied, and then the identifier of the copied target configuration file is replaced with the working image layer identifier to obtain the working configuration file.

[0109] For the description file of the working image, an initial description file is generated based on a preset description file template, the image layer field and the configuration file field in the initial description file, the working image layer identifier is written in the image layer field in the initial description file, and the index relationship to the working configuration file is written in the configuration file field in the initial description file to obtain the working description file. Through the working description file, the container corresponding to the working image can be mounted in the manner of steps S210 to S250 as described above. The container corresponding to the working image retains the working environment after the container corresponding to the target image is run, and the persistence of the container can be achieved.

[0110] It can be understood that when mounting the container corresponding to the working image, the target image layer is the working image layer, and there is a reference relationship between the working image layer and the last image layer in the arrangement order in the target image. There is a reference relationship between the working storage block and the storage block of the last image layer in the arrangement order in the target image. In this way, the storage blocks corresponding to each image layer in the target image can be referenced through the working storage block to realize the mounting of the container.

[0111] In this embodiment, the image layer in the image is stored in the corresponding storage block, and the storage block is set to correspond to the image layer identifier. Therefore, when the container is started, the corresponding storage block is obtained through the image layer identifier, and the container can be mounted and started through the storage block, without downloading the complete image, which can improve the efficiency of container startup. At the same time, it is proposed that after the container is started, when the container is running, the running data can be used as a new image, and the working state of the container is retained to achieve container persistence. In this process, there is no need to upload the complete working image file and the working description file in the image repository. The working image layer identifier is determined by a blank file, and the storage block and the working configuration file corresponding to the working image layer identifier are indexed in the working description file, so that the corresponding container can be mounted later, which speeds up the speed of container persistence.

[0112] Figure 3 This is a structural diagram of a container startup system shown in an exemplary embodiment. The container startup system may include an image repository, a first storage block production module, a second storage block production module, a preset storage block set and a container startup platform. The first storage block production module obtains the image from the image reference, and then reads the image description file to decompress the image layer layer by layer into the corresponding storage block to form a complete file system for use when the container is started.

[0113] The container startup platform can be a conventional container creation platform, such as the containerd platform, but in the container startup platform, a plug-in or a function can be set to find the storage block corresponding to the image during the container startup phase and mount it to the host. The storage block is used as the container's file system to start the container, thereby skipping the image download process, thereby achieving the purpose of accelerating the image startup. After that, the reading and writing of the container file system will be performed on this storage block.

[0114] The default storage block set is a Ceph cluster, which interacts with other modules through interfaces.

[0115] The second storage block production module acts on the container persistence stage. It quickly creates a snapshot of the mounted storage block of the current container working environment by calling the interface of the preset storage block set, and then modifies the image description file and configuration file, points the image layer to the snapshot of the newly created storage block, and finally uploads the modified description file and configuration file to form a new image. This method uses the characteristics of Ceph RBD to quickly save containers, and in the process of uploading images, only the two metadata files, manifest and config, need to be updated to the image repository, without uploading large-size Layer files, making container persistence more efficient.

[0116] In some embodiments, taking the containerd platform obtaining the target storage block through step S230 as an example, in the first storage block production module, specify the image of the corresponding storage block to be produced, download the description file of the corresponding image in the image warehouse to the local, parse the description file to obtain the image layer identifiers of all image layers, form an array Layers, call the interface of the preset storage block set to create an initial storage block, name the initial storage block with the corresponding image layer identifier in the Layers array, download the image layer file content in Layers[0], and decompress it into the initial storage block named by the corresponding image layer identifier. If the length of Layers is greater than 1, traverse Layers, and for Layers, There is a corresponding array RBD-Layers, each value in the RBD-Layers array corresponds to an initial storage block, the image layer identifier of Layer[i] corresponds to the initial storage block of RBD-Layers[i], the interface of the preset storage block set is called to create an RBD snapshot based on RBD-Layers[i-1], and the snapshot is cloned to generate a new RBD. The snapshot and the new RBD are both named with Layers[i]. The content of the Layer[i] file is downloaded and decompressed to RBD-Layers[i], so that the content of the corresponding image layer file is stored in the initial storage block. If the storage blocks corresponding to each image layer in the target image can be obtained by the above method, then according to Figure 2 The relevant embodiment in the above method starts the container corresponding to the target image.

[0117] In the container startup platform, when the container startup platform creates a container, it will traverse each image layer in the image description file, pass in the image layer identifier to locate the local storage location of the storage block corresponding to the image layer, and finally prepare the container file system based on the image layer. The reading and writing of the container will be carried out in this file system.

[0118] In one embodiment, when the containerd platform determines to start a container, taking the container of the target image as an example, the containerd platform will obtain the following method input parameters: context (execution context information), key (identifier of the current layer, which is automatically generated by the containerd platform), parent (parent key, indicating the next image layer of the image layer corresponding to the key), opts (relevant information of the image layer in the target image corresponding to the key).

[0119] If the key is prefixed with extract, it means that the image layer is currently being processed, that is, the image layer corresponding to the parent is not the last image layer in the target image. The image layer identifier corresponding to the key is obtained from opts, and the interface of the preset storage block set is called to find the corresponding storage block. If it is found, a prompt message is returned to help the container startup platform skip the download of the image layer, and the image layer corresponding to the parent is not used as the target image layer; if it is not found, an error is returned and the container startup is exited.

[0120] If the key is not prefixed with extract, it indicates that a container read-write file system needs to be created, that is, the image layer corresponding to the parent is the last image layer in the target image. The interface of the preset storage block set is called to find the storage block referenced by the parent (the target storage block). If it does not exist, an error is returned and the process is exited. If it is found; get the container ID (identifier) ​​from the key, call the interface of the preset storage block set to create and clone the snapshot based on the parent's storage block to generate a new storage block, and the device is named after the container ID; call the interface of the preset storage block set to map the storage block of the container ID to the local, return the device path to the container startup platform, and mount it as the root file system of the container.

[0121] In the second storage block production module, you can specify the container ID and new image name (working image) to be saved, call the interface of the preset storage block set to find the storage block corresponding to the container ID (the storage block corresponding to the container of the target image), if not found, return an error and exit; generate a random UUID (Universally Unique Identifier) ​​and write it into a blank file as the image layer file, and calculate the sha256 (Secure Hash Algorithm256-bit, a cryptographic hash function) value is used as the working image layer identifier of the working image layer, and the interface of the preset storage block set is called to create and clone snapshots based on the storage block corresponding to the container ID, generate a new working storage block, name it according to the working image layer identifier obtained in the previous step, copy the configuration file (target configuration file) of the container base image, clear the contents of the diffs array, obtain the working configuration file, and add the working image layer identifier to the array, create an initial description file of the working image, write the working image layer identifier into the image layer field, and write the index relationship to the working configuration file into the configuration file field in the initial description file to obtain the working description file, and upload the working image layer file, working configuration file, and working description file generated in the previous steps to the image library in turn.

[0122] Figure 4 : is a structural diagram of a container starting device shown in an exemplary embodiment, and the container starting device 400 includes:

[0123] A target description file acquisition module 410 is used to acquire a target description file of a target image, where the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers;

[0124] The target storage block acquisition module 430 is used to acquire the target storage block corresponding to the target image layer in the target image based on the image layer identifiers of each image layer in the target image, where different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer;

[0125] The container startup module 450 is used to mount and start the container corresponding to the target image based on the target storage block.

[0126] In one implementable manner, there is an arrangement order between at least one image layer in the target image, and there is a reference relationship between storage blocks corresponding to each image layer based on the arrangement order; the target storage block acquisition module includes:

[0127] A target image layer acquisition unit, used to use the image layer located at the last layer in the arrangement order as the target image layer;

[0128] The target storage block acquisition unit is used to acquire the corresponding target storage block in the preset storage block set based on the image layer identifier of the target image layer, and the target storage block is used to reference the storage blocks of other image layers in the target image except the target image layer based on the reference relationship.

[0129] In one achievable manner, at least one image layer in the target image has an arrangement order, and storage blocks corresponding to each image layer have a reference relationship based on the arrangement order; the container startup module includes:

[0130] The mounting unit is used to map the target storage block to the target location and obtain the mounting file of the target location;

[0131] The container startup unit is used to read the mount file at the target location to access the target storage block through the mount file, and reference the storage blocks of other image layers in the target image except the target image layer according to the reference relationship to start the container corresponding to the target image.

[0132] In one possible implementation, the container startup device further includes:

[0133] An initial storage block creation module is used to create a corresponding initial storage block for each image layer in the target image. The initial storage block is named according to the image layer identifier of the corresponding image layer.

[0134] The storage block acquisition module is used to copy the image content in each image layer in the target image into the corresponding initial storage block to obtain the storage block corresponding to each image layer.

[0135] In one possible implementation, the container startup device further includes:

[0136] A blank file generation module is used to generate a blank file when the container corresponding to the target image is running;

[0137] A working image layer identification acquisition module is used to obtain a working image layer identification corresponding to a working image layer in a working image based on a blank file. The working image represents the working environment of a container corresponding to a target image at runtime. The working image includes a working image layer.

[0138] A working storage block acquisition module is used to store the data generated by the container runtime corresponding to the target image as the image content of the working image layer in the working storage block, and the working storage block is named as the working image layer identifier;

[0139] The working description file acquisition module is used to generate a working description file of the working image based on the working image layer identifier and the target configuration file of the target image. The working description file is used to locate the working storage block and the configuration file to generate a container corresponding to the working image.

[0140] In an implementable manner, the target description file indicates a target configuration file of a target image; and the work description file acquisition module includes:

[0141] A working configuration file obtaining unit, used to replace the identifier in the target configuration file with the working image layer identifier to obtain the working configuration file;

[0142] An initial description file acquisition unit, used to generate an initial description file based on a preset description file template;

[0143] The work description file acquisition unit is used to write the work image layer identifier into the image layer field in the initial description file, and write the index relationship to the work configuration file into the configuration file field in the initial description file to obtain the work description file.

[0144] In one implementable manner, the target description file indicates the image layer file corresponding to each image layer in the target image; the working image layer identification acquisition module includes:

[0145] A working image layer file generating unit, used for writing a random field into a blank file, and using the blank file with the random field written into it as a working image layer file of the working image layer;

[0146] The working image layer identifier obtaining unit is used to generate a working image layer identifier based on the working image layer file.

[0147] The container starting device provided in this embodiment can be used to execute the above-mentioned container starting method. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.

[0148] Figure 5 is a block diagram of an electronic device according to an exemplary embodiment. Figure 5 The electronic device 500 may include: a processor 51 and a memory 52, wherein the processor 51 and the memory 52 can communicate; illustratively, the processor 51 and the memory 52 communicate via a communication bus 53, the memory 52 is used to store instructions, and the processor 51 is used to call the instructions in the memory to execute the container startup method shown in any of the above method embodiments.

[0149] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the present application may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

[0150] The present application provides a computer-readable storage medium, on which computer-executable instructions are stored; when the computer-executable instructions are executed by a processor, they are used to implement a container startup method as described in any of the above embodiments.

[0151] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the above container startup method is implemented.

[0152] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0153] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A container startup method, characterized in that: include: Obtain a target description file of a target image, where the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers; Based on the image layer identifiers of each image layer in the target image, obtaining a target storage block corresponding to the target image layer in the target image, where different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer; Based on the target storage block, a container corresponding to the target image is mounted and started.

2. The method according to claim 1, characterized in that There is an arrangement order between at least one image layer in the target image, and there is a reference relationship between storage blocks corresponding to each image layer based on the arrangement order; obtaining a target storage block corresponding to a target image layer in the target image based on the image layer identifier of each image layer in the target image includes: The last image layer in the arrangement order is used as the target image layer; A corresponding target storage block is obtained from a preset storage block set based on the image layer identifier of the target image layer, and the target storage block is used to reference storage blocks of other image layers in the target image except the target image layer based on the reference relationship.

3. The method according to claim 1, characterized in that There is an arrangement order between at least one image layer in the target image, and there is a reference relationship between storage blocks corresponding to each image layer based on the arrangement order; and mounting and starting a container corresponding to the target image based on the target storage block includes: Mapping the target storage block to a target location to obtain a mount file at the target location; The mount file at the target location is read to access the target storage block through the mount file, and the storage blocks of other image layers in the target image except the target image layer are referenced according to the reference relationship to start the container corresponding to the target image.

4. The method according to claim 1, characterized in that: Before obtaining the target description file of the target image, the method further includes: For each image layer in the target image, create a corresponding initial storage block, where the name of the initial storage block is the image layer identifier of the corresponding image layer; The image content in each image layer in the target image is copied into the corresponding initial storage block to obtain the storage block corresponding to each image layer.

5. The method according to claim 1, characterized in that After mounting and starting the container corresponding to the target image based on the target storage block, the method further includes: When the container corresponding to the target image is running, a blank file is generated; Based on the blank file, obtain a working image layer identifier corresponding to a working image layer in the working image, wherein the working image represents a working environment of a container corresponding to the target image at runtime, and the working image includes the working image layer; The data generated when the container corresponding to the target image is running is used as the image content of the working image layer, and stored in a working storage block, where the working storage block is named as the working image layer identifier; A working description file of the working image is generated based on the working image layer identifier and the target configuration file of the target image, and the working description file is used to locate the working storage block and the configuration file to generate a container corresponding to the working image.

6. The method according to claim 5, characterized in that The target description file indicates a target configuration file of the target image; and generating the working description file of the working image based on the working image layer identifier and the target configuration file of the target image includes: Replacing the identifier in the target configuration file with the working image layer identifier to obtain a working configuration file; Generate an initial description file based on a preset description file template; The working image layer identifier is written into the image layer field in the initial description file, and the index relationship of the working configuration file is written into the configuration file field in the initial description file to obtain the working description file.

7. The method according to claim 5, characterized in that The target description file indicates the image layer file corresponding to each image layer in the target image; and obtaining the working image layer identifier corresponding to the working image layer in the working image based on the blank file includes: Write a random field into the blank file, and use the blank file with the random field written into it as the working image layer file of the working image layer; A working image layer identifier is generated based on the working image layer file.

8. A container starting device, characterized in that: include: A target description file acquisition module, used to acquire a target description file of a target image, wherein the target description file indicates at least one image layer of the target image, and different image layers correspond to different image layer identifiers; A target storage block acquisition module is used to acquire a target storage block corresponding to a target image layer in the target image based on the image layer identifiers of each image layer in the target image, where different image layer identifiers correspond to different storage blocks, and the target storage block stores the image content of the target image layer; The container startup module is used to mount and start the container corresponding to the target image based on the target storage block.

9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory; the memory is used to store instructions; the processor is used to execute the instructions in the memory, so that the electronic device executes the method as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.

11. A computer program product, characterized in that The method comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.