A method, device, storage medium and electronic device for building a container image

By obtaining the basic image and source code packages, and using the mounted compilation toolkit and compilation software for compilation, the problem of excessive container image and long startup time in the prior art is solved, and a smaller image size and faster container startup time are achieved.

CN111966463BActive Publication Date: 2025-02-28JIANGSU ANCHAO CLOUD SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010835896.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-18
Publication Date
2025-02-28
Estimated Expiration
2040-08-18

AI Technical Summary

Technical Problem

In the prior art, the compiled container image is large, and it is inconvenient to store and the time is long to start the container using the image.

Method used

By obtaining the basic image and source code package, using the mounted compilation toolkit and compilation software for compilation, a business image containing the basic image and source code package is obtained, and uploaded to the mirror warehouse for storage.

Benefits of technology

Reduces the size of the mirror, is easy to save, and greatly reduces the time of container creation when starting the container, improving the speed and efficiency of highly available switching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, storage medium and electronic device for constructing a container image, the method comprising: obtaining a base image and a source code package; compiling the base image and the source code package according to a mounted compilation toolkit and compilation software to obtain a business image containing the base image and the source code package. By implementing the present invention, when compiling an image, only the base image and the source code package are compiled; at the same time, the compilation toolkit can be pre-installed on the compiled host server and the compilation software can be saved. When the base image is started as a container, the directory where the compilation toolkit is installed and the directory where the compilation software is saved are mounted to the container, and then the code in the source code package is copied into the container for installation, and the compilation of the image can be completed. As a result, the compiled image only contains the base image and the source code package, so that the business image is small in size and easy to save, and when the image is started as a container, the time for creating the container can be greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud computing technology, and in particular to a method, device, storage medium and electronic device for building a container image. Background Art

[0002] A container image is a special file system obtained by standardizing the application code and its operating environment. It can be directly run on any operating system with a container installed. A container is a unified platform for building, distributing, and running applications, and is used to achieve automated installation, deployment, and upgrades of applications. Since the container image provides various resources required for the container runtime and is the basis for the container to run, before automatically deploying the application based on container technology, it is necessary to build the container image of the application first.

[0003] At present, the following methods are mainly used to build container images: receive image building instructions sent by users, and obtain the code of the application based on the image building instructions; create a container building task, and build the container of the application based on the container building task; compile the application code and other resources used to build the container image in the built container to obtain the container image of the application; receive the image upload instruction sent by users, and upload the built container image to the image server based on the image upload instruction.

[0004] However, in the prior art, when compiling an image, mainstream software is compiled and packaged and the image is constructed in the form of a software package, a basic Docker image, and an image component driver. The image compiled in this way is larger, occupies a larger space when saved, remains unchanged, and takes a long time to start a container using the image. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method, device, storage medium and electronic device for constructing a container image to solve the problem in the prior art that the compiled image is large, inconvenient to store and takes a long time to start a container using the image.

[0006] The technical solution proposed by the present invention is as follows:

[0007] A first aspect of an embodiment of the present invention provides a method for building a container image, which includes: obtaining a base image and a source code package; compiling the base image and the source code package according to a mounted compilation toolkit and compilation software to obtain a business image containing the base image and the source code package.

[0008] Furthermore, the base image and the source code package are compiled according to the mounted compilation toolkit and compilation software to obtain a business image containing the base image and the source code package, including: installing the compilation toolkit on a compiled host server; pre-saving the compilation software on the compiled host server; starting the base image as a container; mounting the installation directory of the compilation toolkit and the saving directory of the compilation software to the container; copying the code in the source code package to the container for compilation to obtain a business image containing the base image and the source code package.

[0009] Furthermore, the method for constructing the container image also includes: uploading the business image to an image warehouse for storage.

[0010] Furthermore, the method for constructing the container image also includes: generating a local image according to the business image; starting the local image according to the mounted compilation toolkit and compilation software to obtain a running container.

[0011] Furthermore, before starting the local image according to the mounted compilation toolkit and compilation software, the method further includes: installing the compilation toolkit in the server running the container and saving the compilation software.

[0012] Furthermore, before starting the local image according to the mounted compilation toolkit and compilation software, the method further includes: storing the compilation toolkit and compilation software in a shared memory.

[0013] Furthermore, the compilation toolkit includes: any one of a Java package, a C++ package or a Glibc, and the compilation software includes architecture blueprint data and map data.

[0014] A second aspect of an embodiment of the present invention provides a device for building a container image, which includes: an acquisition module, used to acquire a basic image and a source code package; a compilation module, used to compile the basic image and the source code package according to a mounted compilation toolkit and compilation software to obtain a business image containing the basic image and the source code package.

[0015] A third aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method for building a container image as described in the first aspect of the embodiment of the present invention and any one of the first aspects.

[0016] A fourth aspect of an embodiment of the present invention provides an electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the method for building a container image as described in the first aspect of the embodiment of the present invention and any one of the first aspects.

[0017] The technical solution provided by the present invention has the following effects:

[0018] The container image construction method, device, storage medium and electronic device provided by the embodiment of the present invention only compile the basic image and source code package when compiling the image; at the same time, the compilation toolkit can be pre-installed on the compiled host server and the compilation software can be saved. When the basic image is started as a container, the directory where the compilation toolkit is installed and the directory where the compilation software is saved are mounted to the container, and then the code in the source code package is copied into the container for installation, and the image compilation can be completed. As a result, the compiled image only contains the basic image and the source code package, which greatly reduces the size of the image and is easy to save compared to the container image in the prior art. And when the image is started as a container, the time to create the container can be greatly reduced. At the same time, the speed of downloading the image can be increased during high-availability switching, and the high-availability switching time can be reduced.

[0019] The method, device, storage medium and electronic device for constructing a container image provided by an embodiment of the present invention can, when starting a compiled image, use the compilation toolkit and compilation software installed during compilation or pre-install the compilation toolkit and save the compilation software according to the specific server that starts the image, so as to facilitate the operation of the container after starting the image. At the same time, when there are many servers, the compilation toolkit and compilation software can also be saved in a shared memory, which can avoid installing the compilation toolkit and saving the compilation software in multiple servers. In addition, when multiple images are started at the same time in the same server, the compilation toolkit and compilation software mounted on the server can be shared. Therefore, the method for constructing a container image provided by an embodiment of the present invention can reduce the number of installed compilation toolkits and saved compilation software, thereby reducing the corresponding workload. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 is a flowchart of a method for building a container image according to an embodiment of the present invention;

[0022] Figure 2 is a flowchart of a method for building a container image according to another embodiment of the present invention;

[0023] Figure 3 is a structural block diagram of a method and device for building a container image according to an embodiment of the present invention;

[0024] Figure 4 is a structural block diagram of a method and device for building a container image according to another embodiment of the present invention;

[0025] Figure 5 is a structural block diagram of a method and device for building a container image according to another embodiment of the present invention;

[0026] Figure 6 is a schematic diagram of the structure of a computer-readable storage medium provided according to an embodiment of the present invention;

[0027] Figure 7 is a schematic diagram of the structure of an electronic device provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0029] As described in the background technology, the existing container image creation process, such as the container technology based on Docker, is realized through the communication process between the user or client and the Docker host, that is, the Docker host receives the image creation instruction from the user or client, obtains the code of the application based on the image building instruction to form a software package or source code package, and pulls a blank basic Docker image at the same time, and compiles it in the environment corresponding to the compilation toolkit and the compilation software to obtain a business image containing the software package, the basic image, the compilation toolkit and the compilation software. However, the image contains a lot of content, which is not easy to save, and the image size may reach tens of GB. It may take a long time to create a container based on the image; at the same time, it is time-consuming to download the image when switching to high availability, resulting in a long high availability switching time.

[0030] Based on this, an embodiment of the present invention provides a method for building a container image, such as Figure 1 As shown, the method for building the container image includes the following steps:

[0031] Step S101: Obtain the base image and source code package; specifically, in the process of image building, it is necessary to obtain the code of the application, which can be developed by the user himself or obtained from existing code, and the code can be saved in the source code package. At the same time, a general blank official image, i.e., the base image, is also required when compiling the image, such as a pure version of Windows, including CentOS, Ubuntu, Suse, etc. When building the image for the first time, the required base image can be pulled from the image warehouse. The pulled base image can be saved locally, and there is no need to pull it again when building the image next time, and it can be directly obtained locally.

[0032] Step S102: Compile the base image and source code package according to the mounted compilation toolkit and compilation software to obtain a business image containing the base image and source code package. Optionally, when compiling the base image and source code package, the base image can be started as a container first, and then the code in the source code package can be copied into the container for installation. Specifically, before compiling, a compilation toolkit, such as a Java package, a C++ package or Glibc, etc., can be pre-installed on the compilation host server, and the compilation software such as architecture blueprint data and map data can be pre-saved on the compilation host server; when compiling, the directory where the compilation toolkit is installed and the directory where the compilation software is saved can be mounted to the constructed container, that is, the mounted compilation toolkit and compilation software are equivalent to providing a compilation environment for the compilation process, thereby, the base image and source code package can be compiled under the compilation environment to obtain a business image containing the base image and source code package.

[0033] The container image construction method provided by the embodiment of the present invention only compiles the base image and the source code package when compiling the image; at the same time, the compilation toolkit can be pre-installed on the compiled host server and the compilation software can be saved. When the base image is started as a container, the directory where the compilation toolkit is installed and the directory where the compilation software is saved can be mounted to the container, and then the code in the source code package is copied into the container for installation, and the image compilation can be completed. As a result, the compiled image only contains the base image and the source code package, which greatly reduces the size of the image and is easy to save compared to the container image in the prior art. And when the image is started as a container, the time to create the container can be greatly reduced. At the same time, the speed of downloading the image can be increased during high availability switching, and the high availability switching time can be reduced.

[0034] In one embodiment, the container image construction method further includes: uploading the business image to a container repository for storage. Specifically, after the image compilation is completed, the compiled business image in the host server can be uploaded to the container repository (Registry) for storage. In addition, since the compiled business image is smaller in size, more images can be stored in the repository.

[0035] Optionally, the upload process can be implemented with the assistance of the client. Specifically, the user sends a request with a certificate to the index of the registry to request the assignment of a library name. Among them, the index is responsible for and maintains information about user accounts, image verification, and public namespaces. After the authentication is successful and the namespace is available, the library name is also assigned. The index responds and returns a temporary token. The business image to be uploaded is pushed to the registry together with the token. The registry and index confirm that the token is authorized, and then start reading the push stream after the index verification, and finally complete the upload of the business image.

[0036] In one embodiment, if Figure 2 As shown, the method for building the container image also includes the following steps:

[0037] Step S201: Generate a local image according to the business image; specifically, when a business image needs to be started, the corresponding business image can be searched and downloaded from the container repository to obtain a local image.

[0038] Step S202: Start the local image according to the mounted compilation toolkit and compilation software to obtain a running container. Specifically, when the server that starts the image and the server that compiles are the same host server, the directory where the compilation toolkit is installed and the directory where the compilation software is stored in the compilation server can be directly mounted to the container formed by starting the local image, thereby achieving normal operation of the container. At the same time, when multiple containers are running in one server, the multiple containers can share the mounted compilation toolkit and compilation software.

[0039] In one embodiment, when the server that starts the image and the server that compiles are not the same host server, for example, when the image needs to be started in the host server where the production environment is located, the compilation toolkit can be pre-installed in the host server and the compilation software, such as Java packages and architecture blueprints, maps and other data, can be saved. The installation directory of the Java package and the storage directory of the corresponding data are mounted in the container formed by starting the local image, thereby realizing the normal operation of the container.

[0040] In one embodiment, when multiple servers need to start an image, in order to avoid installing a compilation toolkit and saving compilation software in each server, the compilation toolkit and compilation software can be saved in a shared memory; when starting the image in the server, the compilation toolkit and compilation software in the shared memory can be remotely mounted to the corresponding server through the network. In this way, the number of installed compilation toolkits and saved compilation software can be reduced, and the corresponding workload can be reduced.

[0041] The method for constructing a container image provided by an embodiment of the present invention can, when starting a compiled image, use the compilation toolkit and compilation software installed during compilation or pre-install the compilation toolkit and save the compilation software according to the specific server that starts the image, so as to facilitate the operation of the container after starting the image. At the same time, when there are many servers, the compilation toolkit and compilation software can also be saved in a shared memory, which can avoid installing the compilation toolkit and saving the compilation software in multiple servers. In addition, when multiple images are started at the same time in the same server, the compilation toolkit and compilation software mounted on the server can be shared. Therefore, the method for constructing a container image provided by an embodiment of the present invention can reduce the number of installed compilation toolkits and saved compilation software, thereby reducing the corresponding workload.

[0042] The embodiment of the present invention also provides a container image construction device, such as Figure 3 As shown, the container image building device includes:

[0043] The acquisition module 1 is used to acquire the basic image and the source code package; for details, please refer to the relevant description of step S101 in the above method embodiment.

[0044] Compilation module 2 is used to compile the basic image and source code package according to the mounted compilation toolkit and compilation software to obtain a business image including the basic image and source code package. For details, please refer to the relevant description of step S102 in the above method embodiment.

[0045] The container image construction device provided by the embodiment of the present invention only compiles the basic image and the source code package when compiling the image; at the same time, the compilation toolkit can be pre-installed on the compiled host server and the compilation software can be saved. When the basic image is started as a container, the directory where the compilation toolkit is installed and the directory where the compilation software is saved can be mounted to the container, and then the code in the source code package is copied into the container for installation, and the image compilation can be completed. As a result, the compiled image only contains the basic image and the source code package, which greatly reduces the size of the image and is easy to save compared to the container image in the prior art. And when the image is started as a container, the time to create the container can be greatly reduced. At the same time, the speed of downloading the image can be increased during high availability switching, and the high availability switching time can be reduced.

[0046] In one embodiment, if Figure 4 As shown, compilation module 2 includes:

[0047] The installation module 21 is used to install the compilation tool package on the compilation host server.

[0048] The saving module 22 is used to save the compiled software in advance on the compiled host server.

[0049] The startup module 23 is used to start the basic image as a container.

[0050] The mounting module 24 is used to mount the installation directory of the compilation toolkit and the storage directory of the compilation software to the container.

[0051] The compiling submodule 25 copies the code in the source code package to the container for compilation to obtain a business image including the base image and the source code package.

[0052] In one embodiment, if Figure 5 As shown, the container image construction device also includes: a storage module 3, which is used to upload the business image to the image warehouse for storage.

[0053] In one embodiment, if Figure 5 As shown, the container image building device also includes:

[0054] The download module 4 is used to generate a local image according to the business image; for details, please refer to the relevant description of step S201 in the above method embodiment.

[0055] The running module 5 is used to start the local image according to the mounted compilation toolkit and compilation software to obtain the running container. For details, please refer to the relevant description of step S202 in the above method embodiment.

[0056] The container image construction device provided by the embodiment of the present invention can use the compilation toolkit and compilation software installed during compilation or pre-install the compilation toolkit and save the compilation software according to the specific server that starts the image when starting the compiled image, so as to facilitate the operation of the container after starting the image. At the same time, when there are many servers, the compilation toolkit and compilation software can also be saved in a shared memory, which can avoid installing the compilation toolkit and saving the compilation software in multiple servers. In addition, when multiple images are started at the same time in the same server, the compilation toolkit and compilation software mounted on the server can be shared. Therefore, the container image construction device provided by the embodiment of the present invention can reduce the number of installed compilation toolkits and saved compilation software, thereby reducing the corresponding workload.

[0057] For a detailed description of the functions of the device for building a container image provided in an embodiment of the present invention, please refer to the description of the method for building a container image in the above embodiment.

[0058] The embodiment of the present invention also provides a storage medium, such as Figure 6As shown, a computer program 601 is stored thereon, and when the instruction is executed by the processor, the steps of the method for building a container image in the above embodiment are implemented. The storage medium also stores audio and video stream data, feature frame data, interaction request signaling, encrypted data, and preset data size, etc. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, abbreviated: HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.

[0059] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0060] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, the electronic device may include a processor 51 and a memory 52, wherein the processor 51 and the memory 52 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.

[0061] The processor 51 may be a central processing unit (CPU). The processor 51 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.

[0062] The memory 52 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as the corresponding program instructions / modules in the embodiment of the present invention. The processor 51 executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory 52, that is, the method for building a container image in the above method embodiment is implemented.

[0063] The memory 52 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created by the processor 51, etc. In addition, the memory 52 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 52 may optionally include a memory remotely arranged relative to the processor 51, and these remote memories may be connected to the processor 51 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0064] The one or more modules are stored in the memory 52 and when executed by the processor 51, perform the following steps: Figure 1 -2 is a method for building a container image in the embodiment shown in FIG.

[0065] For details of the above electronic equipment, please refer to Figure 1 to Figure 2 The corresponding related descriptions and effects in the illustrated embodiments can be understood and will not be repeated here.

[0066] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for building a container image, characterized in that: include: Get the base image and source package; Compile the base image and the source code package according to the mounted compilation toolkit and compilation software to obtain a business image including the base image and the source code package; Compiling the base image and the source code package according to the mounted compilation toolkit and compilation software to obtain a business image containing the base image and the source code package, including: Install the compilation toolkit on the compilation host server; Pre-save the compiled software on the compilation host server; Starting the base image as a container; Mounting the installation directory of the compilation toolkit and the storage directory of the compilation software to the container; Copying the code in the source code package to the container for compilation to obtain a business image including the base image and the source code package; Generate a local image according to the business image; Storing the compilation toolkit and the compilation software in a shared memory; The local image is started according to the mounted compilation toolkit and compilation software to obtain a running container, wherein when multiple containers are run in a server, the multiple containers share the mounted compilation toolkit and compilation software.

2. The method for constructing a container image according to claim 1, characterized in that: Also includes: The business image is uploaded to the image warehouse for storage.

3. The method for constructing a container image according to claim 1, characterized in that: Before starting the local image according to the mounted compilation toolkit and compilation software, the following is also included: The compilation toolkit is installed in the server running the container and the compilation software is saved.

4. The method for constructing a container image according to claim 1, characterized in that: The compilation toolkit includes: any one of a Java package, a C++ package or a Glibc, and the compilation software includes architecture blueprint data and map data.

5. A container image construction device, characterized in that: include: Acquisition module, used to obtain basic images and source packages; A compiling module, used to compile the base image and the source code package according to the mounted compiling toolkit and compiling software to obtain a business image including the base image and the source code package; Compiling the base image and the source code package according to the mounted compilation toolkit and compilation software to obtain a business image containing the base image and the source code package, including: Install the compilation toolkit on the compilation host server; Pre-save the compiled software on the compilation host server; Starting the base image as a container; Mounting the installation directory of the compilation toolkit and the storage directory of the compilation software to the container; Copying the code in the source code package to the container for compilation to obtain a business image including the base image and the source code package; The device also includes: Download module, used to generate local image based on business image; A shared module, used for storing the compilation toolkit and the compilation software in a shared memory; The running module is used to start the local image according to the mounted compilation toolkit and compilation software to obtain a running container. When multiple containers are run in a server, the multiple containers share the mounted compilation toolkit and compilation software.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method for building a container image according to any one of claims 1 to 4.

7. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method for building a container image according to any one of claims 1 to 4 by executing the computer instructions.

Citation Information

Patent Citations

  • Method for realizing high-speed and safe server cluster management through FPGA virtualization deployment

    CN111124607A

  • Automatic application containerization and mirror image backup release method

    CN111198744A