A method and system for container image construction and dynamic injection
By decoupling container images into basic support images, runtime images and application images, and building file signature indexes based on index thresholds, dynamically loading and injecting container layers, the problem of resource waste and performance degradation caused by the increase in container images is solved. , realizes efficient storage and rapid deployment, and improves the flexibility and response speed of container applications.
Patent Information
- Application Number
- CN202410585945.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The continuous increase in the scale of container images has led to an increase in the time spent on mirroring construction, the demand for storage space increases, the image transmission or distribution time is extended, and the proportion of effective program content is too low, resulting in waste of resources and performance degradation, and low update timeliness and low efficiency.
Decoupling of traditional standard images into basic support images, runtime images and application images, build file signature indexes based on index thresholds, and dynamically load and inject container layers through file entities or index pull forms to realize image layered packaging and File-level sharing.
The image volume compression is achieved, storage and distribution efficiency are improved, and the flexibility and adaptability of container applications are improved, resource waste and network bandwidth occupation are reduced, system maintenance and upgrade processes are simplified, and response speed and scalability are improved.
Smart Images

Figure CN118170500B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing technology, and in particular to a method and system for container image construction and dynamic injection. Background Art
[0002] A container image is a lightweight, independent form of software packaging that packages an application and all its dependencies together to ensure that the application runs consistently in different environments. The basis of container images is the Union File System technology, which allows multiple file systems to be mounted to the same directory to form a unified file system view. In a container image, different layers can be integrated together through the Union File System technology to provide a unified file system for the container. This mechanism enables containers to share the same basic file system and implements the hierarchical storage structure of container images.
[0003] Container image technology uses underlying technologies such as joint file systems and copy-on-write to achieve efficient application packaging and distribution, bringing revolutionary changes to software development and deployment. The emergence of container images makes it easier for applications to be deployed across platforms, iterate quickly, and deliver continuously, greatly improving the productivity and efficiency of development teams.
[0004] With the popularization and application of containerization technology, the container loads the operating environment data such as the operating system as a whole in the software image package. While providing a fast and convenient "out-of-the-box" feature, the container image contains all the operating environment required for the service, resulting in the continuous increase in the scale of the image. When the general container image construction technology is applied to the corresponding information system field, the large volume of the container image causes many problems, such as increased image construction time, increased storage space requirements, and longer image transmission or distribution time. It is particularly noteworthy that the actual effective program content of the container image may only account for a small part of the entire image. The proportion of effective content is too low, resulting in resource waste and performance degradation. At the same time, in order to adapt to changing tasks and application scenarios, information systems face changes in software requirements and rapid iteration requirements, so that each software update needs to be "all-in-one" packaged image, and a lot of time is spent on building container images, resulting in low update timeliness and low update efficiency. Summary of the invention
[0005] The present invention intends to provide a method and system for container image construction and dynamic injection to solve the deficiencies in the prior art. The technical problem to be solved by the present invention is achieved through the following technical solutions.
[0006] The method for building and dynamically injecting a container image provided by the present invention includes:
[0007] Decouple the traditional standard image into basic support image, runtime image and application image;
[0008] Build file signature indexes corresponding to the basic support image, runtime image, and application image based on the index threshold, and upload the file entities corresponding to the file signature indexes to the cloud file storage system;
[0009] Files are dynamically loaded and injected into the corresponding layer of the container from the base support image, runtime image or application image through file entity injection or file index pull.
[0010] In the above scheme, the file signature indexes corresponding to the basic support image, the runtime image and the application image are constructed based on the index threshold, including:
[0011] Create corresponding file signature indexes for files in the basic support image, runtime image, and application image whose sizes are greater than the index threshold.
[0012] In the above scheme, the calculation formula of the index threshold is:
[0013] ;
[0014] Among them, S is the index threshold, x i ∈X, X is the file size list obtained by scanning the cloud file storage system and recording the size of each file, represents the average size of all files. Indicates the threshold value determined according to the disk space limit, D max is the maximum available disk space, and α is an adjustment factor to ensure that large files after indexing do not take up too much disk space. represents the threshold value determined according to the time complexity of indexing and system performance requirements, T max is the maximum index creation time allowed by the cloud file storage system, and O(f) is the time complexity of the Blake2b algorithm to create an index on a unit file.
[0015] In the above scheme, when files are dynamically loaded and injected from the basic support image, runtime image or application image into the corresponding layers of the container in the form of file entity injection, when the container is started or during operation, the basic support image, runtime image or application image is triggered according to the decoupling division rules of the traditional standard image, and the corresponding files are directly loaded and injected from the basic support image, runtime image or application image into the corresponding layers of the container through the file copying injection mechanism.
[0016] In the above scheme, when files are dynamically loaded and injected into the corresponding layers of the container from the basic support image, runtime image or application image respectively through file index pulling, the file entity corresponding to the file signature index is pulled from the cloud file storage system and shared to the corresponding layer of the container or the file is shared to the corresponding layer of the container through file mounting.
[0017] In the above solution, when the file signature index has a file entity in the local file sharing pool, the file is shared to the corresponding layer of the container by file mounting.
[0018] In the above scheme, when the file entity does not exist in the local file sharing pool according to the file signature index, the local file sharing pool pulls the corresponding file entity from the cloud file storage system based on the file signature index, and shares the file to the corresponding layer of the container through file mounting.
[0019] In the above solution, after the file signature index is constructed, the basic support image, runtime image and application image all include the file entity and the file signature index.
[0020] In the above solutions, the basic support image, runtime image and application image all adopt a single-layer or multi-layer structure.
[0021] The system for building and dynamically injecting container images provided by the present invention adopts the method for building and dynamically injecting container images as described above to build and dynamically inject container images, and the system includes:
[0022] Decoupling and partitioning module, used to decouple and partition the traditional standard image into basic support image, runtime image and application image;
[0023] A file signature index building module is used to build file signature indexes corresponding to the basic support image, runtime image, and application image respectively based on the index threshold, and upload the file entity corresponding to the file signature index to the cloud file storage system;
[0024] The loading and injection module is used to dynamically load and inject files from the basic support image, runtime image or application image into the corresponding layer of the container through file entity injection or file index pull.
[0025] The embodiments of the present invention include the following advantages:
[0026] The method and system for container image construction and dynamic injection provided by the embodiment of the present invention decouple the traditional standard image and divide it into a basic support image, a runtime image and an application image. Different components or functions are divided according to independent logical units, and the packaged image volume is relatively small, which is conducive to efficient storage and rapid distribution of the image; the traditional standard image is decoupled and divided into a basic support image, a runtime image and an application image. The basic support image, the runtime image and the application image can be independently and quickly constructed and deployed, thereby realizing layered image packaging. Since the layered image packaging can reuse the existing image layer, it can be completed quickly when a new image is constructed, which speeds up the deployment. When a component needs to be updated, it does not need to be completely repackaged, but only the image of a component needs to be updated, and the operation and maintenance are more flexible. According to actual needs, additional components, configuration information or files can be dynamically injected into the container when the container is running, thereby improving the flexibility and adaptability of the container application. During the operation of the container, updating a component or expanding a function does not require To re-upload and restart the container image, you only need to update some component images; file-level sharing can be achieved between the basic support image, runtime image and application image. File-level sharing between the basic support image, runtime image and application image significantly reduces the amount of data distributed and transmitted, and can also significantly improve the efficiency and performance of the overall system; through file-level sharing, the same file can be directly shared during different container deployment processes, avoiding repeated downloading and storage of the same data, reducing network bandwidth usage and storage resource waste; at the same time, file-level sharing between the basic support image, runtime image and application image is also conducive to unified management and updating of shared files, ensuring file consistency and integrity. By maintaining a centralized file sharing pool, file versions and permissions can be more effectively managed and controlled, simplifying the system maintenance and upgrade process; in addition, file-level sharing also provides more flexible deployment options for container deployment, allowing container applications to start and expand more quickly, further improving the system's responsiveness and scalability. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a flowchart of a method for building and dynamically injecting a container image according to an embodiment of the present invention;
[0028] Figure 2 It is a schematic diagram of the process of splitting a traditional standard image according to an embodiment of the present invention;
[0029] Figure 3 It is a schematic diagram of a process of splitting a complete image of a service catalog software according to an embodiment of the present invention;
[0030] Figure 4 It is a schematic diagram of a process of constructing a file signature index corresponding to each image according to an embodiment of the present invention;
[0031] Figure 5 It is a schematic diagram of a process of dynamically loading and injecting files by pulling files through a file index according to an embodiment of the present invention;
[0032] Figure 6 It is a schematic diagram of the composition of a system for building and dynamically injecting container images according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0034] like Figure 1 As shown, the present invention provides a method for container image construction and dynamic injection, the method comprising the following steps:
[0035] Step S1: Decouple the traditional standard image into a basic support image, a runtime image, and an application image;
[0036] Specifically, in the process of splitting the traditional standard image, the traditional standard image is decoupled and divided into basic support image, runtime image and application image according to the software structure and operation characteristics. For details, please refer to Figure 1 ; The basic support image refers to the root file system roofs that the software depends on at the bottom of the running, the runtime image refers to the basic runtime environment required for program execution, such as Java environment, Python environment, etc., and the application image refers to the executable program package developed for end users, such as the program package of joint planning, comprehensive situation, action monitoring and other software; For example, the service catalog software is developed in Java language. According to the above splitting rules, the complete image of the service catalog software can be decoupled and divided into Kylin operating system image, Java runtime environment image and service catalog Jar package image. For details, please refer to Figure 3 ;
[0037] Specifically: the traditional standard image is decoupled and divided into basic support image, runtime image and application image. When the system business requirements are updated, usually only the application class image needs to be rebuilt, which can effectively shorten the image building time; at the same time, the traditional standard image is decoupled and divided into basic support image, runtime image and application image. Different components or functions are divided according to independent logical units, and the packaged image size is relatively small, which is conducive to efficient storage and rapid distribution of images; in addition, the traditional standard image is decoupled and divided into basic support image, runtime image and application image. The basic support image, runtime image and application image can be independently and quickly built and deployed, realizing layered image packaging. Since the layered image packaging can reuse the existing image layer, it can be completed quickly when building a new image, which speeds up the deployment. When a component needs to be updated, it does not need to be completely repackaged. It is only necessary to update the image of a component, which makes operation and maintenance more flexible.
[0038] Step S2: constructing file signature indexes corresponding to the basic support image, the runtime image, and the application image respectively based on the index threshold, and uploading the file entities corresponding to the file signature indexes to the cloud file storage system;
[0039] Specifically, the file signature index is a digital signature that can uniquely identify the corresponding file, generated by performing a hash operation based on the file content in the basic support image, runtime image, or application image using the Blake2b algorithm;
[0040] Specifically, whether the file exists in the basic support image, runtime image or application image in the form of a file entity or an index is determined by the index threshold S. Since it takes time to form a file signature index, the more files need to establish a signature index, the longer the calculation time. In order to balance the image size and the time required to establish a file signature index, the index threshold S is set. When the size of the file is greater than the index threshold S, a file signature index is established, otherwise no file signature index is established. As a result, the basic support image, runtime image and application image are composed of a mixture of file indexes and files, which greatly compresses the image size. In addition, for the basic support image, runtime image and application image, a corresponding cloud file storage system is provided, and the file entity corresponding to the file signature index is uploaded to the cloud file storage system for subsequent dynamic on-demand download.
[0041] Specifically, considering file size distribution, system resource limitations, time complexity of indexing, and performance requirements, the index threshold S is designed to ensure that the system can quickly index and maintain efficient performance. The calculation formula of the index threshold S is:
[0042] ;
[0043] Among them, x i ∈X, X is the file size list obtained by scanning the cloud file storage system and recording the size of each file, represents the average size of all files. Indicates the threshold value determined according to the disk space limit, D max is the maximum available disk space, and α is an adjustment factor to ensure that large files after indexing do not take up too much disk space. represents the threshold value determined according to the time complexity of indexing and system performance requirements, T max is the maximum index creation time allowed by the cloud file storage system, and O(f) is the time complexity of the Blake2b algorithm to create an index on a unit file;
[0044] Specifically, after constructing the file signature indexes corresponding to the basic support image, runtime image and application image respectively based on the index threshold, the basic support image, runtime image and application image all include the file entity and the file signature index, thereby compressing the image size. When the image size is reduced, the transmission and storage efficiency is improved. For example, with the same bandwidth, the smaller the size, the less transmission time is consumed, the less bandwidth is occupied, and more images can be stored in the same storage space.
[0045] Specifically, uploading the file entity corresponding to the file signature index to the cloud file storage system can solve the problem of obtaining the file entity, realize cloud storage, and share it across the entire network;
[0046] Specifically, the basic support image, runtime image, and application image all adopt a single-layer or multi-layer structure;
[0047] In one embodiment of the present invention, the basic support image, the runtime image and the application image adopt a two-layer structure. The first layer and the second layer of the basic support image, the runtime image and the application image each include multiple file entities and multiple file signature indexes. The file entity corresponding to the file signature index is uploaded to the cloud file storage system. When the file entity corresponding to the file signature index needs to be obtained later, the corresponding file entity is pulled from the cloud file storage system according to the file signature index. For details, please refer to Figure 4 ;
[0048] Step S3: dynamically loading and injecting files from the basic support image, the runtime image or the application image into the corresponding layer of the container by means of file entity injection or file index pull;
[0049] Specifically, when files are dynamically loaded and injected from a basic support image, a runtime image or an application image into corresponding layers of a container respectively in the form of file entity injection, when the container is started or during operation, the basic support image, the runtime image or the application image is triggered according to the decoupling division rule of the traditional standard image, and the corresponding files are directly loaded and injected from the basic support image, the runtime image or the application image into the corresponding layers of the container through the injection mechanism of file copying;
[0050] Specifically, when files are dynamically loaded and injected into the corresponding layer of the container from the basic support image, runtime image or application image respectively through file index pulling, the file entity corresponding to the file signature index is pulled from the cloud file storage system and shared to the corresponding layer of the container or the file is shared to the corresponding layer of the container through file mounting. For details, please refer to Figure 5 ;
[0051] Specifically, when the file signature index exists in the local file sharing pool, the file is shared to the corresponding layer of the container by means of file mounting; when the file signature index does not exist in the local file sharing pool, the local file sharing pool pulls the corresponding file entity from the cloud file storage system based on the file signature index, and shares the file to the corresponding layer of the container by means of file mounting. Therefore, when the same file signature index exists in the same physical node container deployment process, the file can be shared through the local file sharing pool, which can effectively prevent the repeated pulling of the same file, further reduce the amount of data downloaded and improve resource utilization.
[0052] Specifically, by dynamically loading and injecting files from the basic support image, runtime image or application image into the corresponding layer of the container in the form of file index pulling, file-level sharing between the basic support image, runtime image and application image can be achieved. File-level sharing between the basic support image, runtime image and application image significantly reduces the amount of data distributed and transmitted, and can also significantly improve the efficiency and performance of the overall system. Through file-level sharing, the same file can be directly shared during the deployment of different containers, avoiding repeated downloading and storage of the same data, reducing network bandwidth usage and storage resource waste. At the same time, file-level sharing between the basic support image, runtime image and application image is also conducive to unified management and updating of shared files, ensuring the consistency and integrity of files. By maintaining a centralized file sharing pool, file versions and permissions can be more effectively managed and controlled, simplifying the system maintenance and upgrade process. In addition, file-level sharing also provides more flexible deployment options for container deployment, allowing container applications to start and expand more quickly, further improving the system's response speed and scalability.
[0053] Specifically, step S3 can dynamically inject additional components, configuration information or files into the container according to actual needs when the container is running, thereby improving the flexibility and adaptability of container applications. When the container is running, updating a component or expanding a function does not require re-uploading and restarting the container image, but only needs to update some component images.
[0054] like Figure 6 As shown, the present invention provides a system for container image construction and dynamic injection, which uses the above-mentioned method for container image construction and dynamic injection to perform container image construction and dynamic injection, and the system includes:
[0055] Decoupling and partitioning module, used to decouple and partition the traditional standard image into basic support image, runtime image and application image;
[0056] A file signature index building module is used to build file signature indexes corresponding to the basic support image, runtime image, and application image respectively based on the index threshold, and upload the file entity corresponding to the file signature index to the cloud file storage system;
[0057] The loading and injection module is used to dynamically load and inject files from the basic support image, runtime image or application image into the corresponding layer of the container through file entity injection or file index pull.
[0058] It should be noted that the above detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the present application belongs.
[0059] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0060] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein.
[0061] In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or inherent to these processes, methods, products, or apparatuses.
[0062] For ease of description, spatially relative terms, such as "above", "above", "on the upper surface of", "above", etc., may be used herein to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" may include both "above" and "below". The device may also be positioned in other different ways, such as rotated 90 degrees or in other orientations, and the spatially relative descriptions used herein are interpreted accordingly.
[0063] In the above detailed description, reference is made to the accompanying drawings, which form a part of this document. In the accompanying drawings, similar symbols typically identify similar components unless the context indicates otherwise. The illustrated embodiments described in the detailed description, drawings, and claims are not meant to be limiting. Other embodiments may be used, and other changes may be made, without departing from the spirit or scope of the subject matter presented herein.
[0064] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for building and dynamically injecting a container image, characterized in that: The method comprises: Decouple the traditional standard image into basic support image, runtime image and application image; Based on the index threshold, the file signature indexes corresponding to the basic support image, runtime image and application image are constructed respectively. The corresponding file signature indexes are established for the files whose sizes are larger than the index threshold in the basic support image, runtime image and application image, and the file entities corresponding to the file signature indexes are uploaded to the cloud file storage system. The calculation formula of the index threshold is: ; Among them, S is the index threshold, x i ∈X, X is the file size list obtained by scanning the cloud file storage system and recording the size of each file, represents the average size of all files. Indicates the threshold value determined according to the disk space limit, D max is the maximum available disk space, and α is an adjustment factor to ensure that large files after indexing do not take up too much disk space. represents the threshold value determined according to the time complexity of indexing and system performance requirements, T max is the maximum index creation time allowed by the cloud file storage system, and O(f) is the time complexity of the Blake2b algorithm to create an index on a unit file; Files are dynamically loaded and injected into the corresponding layer of the container from the base support image, runtime image or application image through file entity injection or file index pull.
2. The method for container image construction and dynamic injection according to claim 1, characterized in that: When files are dynamically loaded and injected from the basic support image, runtime image or application image into the corresponding layers of the container in the form of file entity injection, when the container is started or during operation, the basic support image, runtime image or application image is triggered according to the decoupling division rules of traditional standard images, and the corresponding files are directly loaded and injected from the basic support image, runtime image or application image into the corresponding layers of the container through the file copying injection mechanism.
3. The method for container image construction and dynamic injection according to claim 1, characterized in that: When files are dynamically loaded and injected into the corresponding layers of the container from the basic support image, runtime image or application image respectively through file index pulling, the file entity corresponding to the file signature index is pulled from the cloud file storage system and shared to the corresponding layer of the container or the file is shared to the corresponding layer of the container through file mounting.
4. The method for container image construction and dynamic injection according to claim 3, characterized in that: When the file signature index has a file entity in the local file sharing pool, the file is shared to the corresponding layer of the container by means of file mounting.
5. The method for container image construction and dynamic injection according to claim 3, characterized in that: When the file signature index does not exist in the local file sharing pool, the local file sharing pool pulls the corresponding file entity from the cloud file storage system based on the file signature index, and shares the file to the corresponding layer of the container through file mounting.
6. The method for container image construction and dynamic injection according to claim 1, characterized in that: After building the file signature index, the basic support image, runtime image and application image all include the file entity and the file signature index.
7. The method for container image construction and dynamic injection according to claim 1, characterized in that: The basic support image, runtime image, and application image all adopt a single-layer or multi-layer structure.
8. A system for building and dynamically injecting container images, which uses the method for building and dynamically injecting container images as described in any one of claims 1 to 7 to build and dynamically inject container images, characterized in that: The system comprises: Decoupling and partitioning module, used to decouple and partition the traditional standard image into basic support image, runtime image and application image; The file signature index construction module is used to construct the file signature indexes corresponding to the basic support image, runtime image and application image respectively based on the index threshold, establish the corresponding file signature indexes for the files in the basic support image, runtime image and application image whose size is greater than the index threshold, and upload the file entities corresponding to the file signature indexes to the cloud file storage system; the calculation formula of the index threshold is: ; Among them, S is the index threshold, x i ∈X, X is the file size list obtained by scanning the cloud file storage system and recording the size of each file, represents the average size of all files. Indicates the threshold value determined according to the disk space limit, D max is the maximum available disk space, and α is an adjustment factor to ensure that large files after indexing do not take up too much disk space. represents the threshold value determined according to the time complexity of indexing and system performance requirements, T max is the maximum index creation time allowed by the cloud file storage system, and O(f) is the time complexity of the Blake2b algorithm to create an index on a unit file; The loading and injection module is used to dynamically load and inject files from the basic support image, runtime image or application image into the corresponding layer of the container through file entity injection or file index pull.
Citation Information
Patent Citations
Mirror image construction and loading method based on mirror image loading in container environment
CN112685134A
Mirror image delay loading method and system suitable for edge AI scene
CN114924845A
