A Docker image rapid construction method, system and medium

CN115599400BActive Publication Date: 2026-10-27KYLIN CORP
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211028250.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-25
Publication Date
2026-10-27
Estimated Expiration
2042-08-25

AI Technical Summary

Technical Problem

但是,上述镜像制作方式存在以下缺点:Docker镜像构建过程缺少引导;Dockerfile编写对于部分不懂Docker的开发人员有一定难度,Dockerfile创建缺少页面形式提示编辑;构建的容器依赖环境不完善,即使构建出容器镜像,也因缺少各种依赖,用户使用困难

Benefits of technology

[0033]1、本发明可针对Dockerfile配置文件中用户导入的二进制程序进行依赖环境自动补全,依赖环境包括Dockerfile配置文件的基础镜像信息以及二进制程序的依赖包信息,并根据完成依赖环境自动补全的Dockerfile配置文件构建Docker镜像,从而实现Docker镜像快速构建,提高Docker镜像的构建效率、提升Docker镜像的构建成功率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115599400B_ABST
    Figure CN115599400B_ABST
Patent Text Reader

Abstract

The application discloses a kind of Docker image quick construction method, system and medium, the Docker image quick construction method of the present application includes: creating or importing Dockerfile configuration file;For the binary program imported by user in Dockerfile configuration file, it is automatically completed to dependence environment, the dependence environment includes the base image information of Dockerfile configuration file and the dependence package information of binary program;Docker image is built according to the Dockerfile configuration file of completing dependence environment automatic completion.The present application can realize Docker image quick construction, improve the construction efficiency of Docker image, improve the construction success rate of Docker image, the present application supports creating or importing Dockerfile configuration file, it can be applied to newly created Dockerfile configuration file, also can be applied to existing Dockerfile configuration file, with the advantage of good universality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention pertains to container image creation technology in the field of computer systems, specifically relating to a method, system, and media for rapid Docker image building. Background Technology

[0002] With the development of Linux systems, various architectures and operating systems have emerged, making it difficult for applications to fully cover all platforms. Deploying across multiple platforms is essential for optimal application performance, making application configuration a complex issue. Docker, an open-source application container engine, allows developers to package their applications and dependencies into a portable container and deploy it to any popular Linux machine. Deploying applications into Docker containers effectively alleviates application migration challenges. Currently, Docker images are created using script files (Dockerfiles), but this process is cumbersome and time-consuming, especially for developers unfamiliar with Docker. The common image creation process involves editing the Dockerfile, creating a base image, and calling the image build command. However, this method has the following drawbacks: the Docker image build process lacks guidance; writing Dockerfiles is difficult for developers unfamiliar with Docker, and the Dockerfile creation process lacks a graphical interface for editing; the built container's dependencies are incomplete, making it difficult for users to use even after the container image is built due to missing dependencies. Summary of the Invention

[0003] The technical problem to be solved by this invention is to provide a method, system, and medium for rapid Docker image building, which addresses the aforementioned problems in the prior art. This invention can build Docker images based on Dockerfile configuration files with autocomplete dependency environments, thereby achieving rapid Docker image building, improving Docker image building efficiency, and increasing the success rate of Docker image building. This invention supports the creation or import of Dockerfile configuration files, so it can be applied to both newly created Dockerfile configuration files and existing Dockerfile configuration files, and has the advantage of good versatility.

[0004] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:

[0005] A method for quickly building Docker images, including:

[0006] S101, Create or import the Dockerfile configuration file;

[0007] S102, perform automatic dependency environment completion for the binary program imported by the user in the Dockerfile configuration file. The dependency environment includes the base image information of the Dockerfile configuration file and the dependency package information of the binary program.

[0008] S103 builds a Docker image based on a Dockerfile configuration file that has completed dependency auto-completion.

[0009] Optionally, step S102 includes:

[0010] S201, perform a horizontal search to determine the base image information, and perform a vertical search to obtain the dependency package information of the binary program;

[0011] S202 writes the base image information and the dependency package information of the binary program into the Dockerfile configuration file.

[0012] Optionally, the lateral search to determine the base image information in step S201 includes:

[0013] S301, Determine the name of the Docker image to be built and initialize the dependency environment variables;

[0014] S302, calculate the image name of the Docker image to be built and the first overlap m of the image in the remote repository. If the maximum value of the first overlap m is greater than a set value, then assign the image in the remote repository corresponding to the maximum value of the first overlap m as the base image of the Docker image to be built to the dependent environment variables; calculate the image name of the Docker image and the second overlap n of the local image. If the maximum value of the second overlap n is greater than a set value, then assign the local image corresponding to the maximum value of the second overlap n as the base image of the Docker image to be built to the dependent environment variables; otherwise, automatically build the base image according to the image name of the Docker image to be built, store it locally, and assign the automatically built base image to the dependent environment variables.

[0015] S303 outputs the image information determined by the lateral search, which depends on the environment variables.

[0016] Optionally, the vertical search for obtaining the dependency package information of the binary program in step S201 includes:

[0017] S401, Initialize the dependency package path array used to record the dependency package paths of the binary program;

[0018] S402 iterates through the binary program in the Dockerfile configuration file by calling the binary dependency query command to obtain the dependency packages that the binary program depends on and the dependency packages that the dependency packages depend on. After deduplicating the dependency packages in the dependency package set, it matches them with the program packages in the software source and writes the paths of the matched program packages into the dependency package path array.

[0019] S403 outputs the dependency package information of the binary program by using the dependency package path array as a vertical search.

[0020] Optionally, importing the Dockerfile configuration file in step S101 includes:

[0021] S501 reads the imported Dockerfile configuration file;

[0022] S502, the lines of the Dockerfile configuration file are parsed to obtain the parsing results. The parsing results include the line type, which includes command line and comment lines. When the line type is command line, the parsing results also include the first string and the subsequent operation content string.

[0023] S503: Add the parsed results of the Dockerfile configuration file to the controls in the graphical interface in the original line order so that the user can modify them. If the user confirms that the modification is complete, proceed to step S102.

[0024] Optionally, step S502 includes: initializing and establishing a decomposition task pool; mapping each line in the Dockerfile configuration file to a decomposition task in the decomposition task pool, and parsing the content of the line through the decomposition task to obtain the parsing result; waiting for the parsing results of all lines until all lines in the Dockerfile configuration file have been parsed, and then jumping to step S503.

[0025] Optionally, in step S503, when adding the parsed result of the Dockerfile configuration file to the controls of the graphical interface in the original line order, the corresponding control for each line includes two sets of fields: the line type and the line content. The line type is a selection control. When the line type is a comment line, the line content is a single edit control to display the comment content. When the line type is a command line, the line content includes two controls: the first string and the operation content string. The first string is a selection control and is bound to a preset set of keywords from the Dockerfile configuration file for selection.

[0026] Optionally, creating the Dockerfile configuration file in step S101 includes:

[0027] S601, Detect the user's operation. If the user confirms that a new row has been added, proceed to step S602; if the user confirms that the modification is complete, proceed to step S603.

[0028] S602, Display the selection control for the line type. If the user selects the line type as a comment line, display the editing control corresponding to the comment content for the user to enter the comment content; if the user selects the line type as a command line, display two controls for the first string and the operation content string for the user to select the first string and enter the operation content string; jump to step S601;

[0029] S603, perform at least one validation, including non-empty validation, on the content of each newly added row. If the validation passes, it is determined that the user has confirmed the modification is complete, and the process jumps to step S102; otherwise, a validation failure message is issued, and the process jumps to step S601.

[0030] Furthermore, the present invention also provides a Docker image rapid building system, including an interconnected microprocessor and a memory, wherein the microprocessor is programmed or configured to execute the Docker image rapid building method.

[0031] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program that is programmed or configured by a microprocessor to execute the Docker image rapid build method.

[0032] Compared with the prior art, the present invention has the following main advantages:

[0033] 1. This invention can automatically complete the dependency environment for binary programs imported by users in Dockerfile configuration files. The dependency environment includes the base image information of the Dockerfile configuration file and the dependency package information of the binary program. Based on the Dockerfile configuration file with completed dependency environment, a Docker image is built, thereby realizing rapid Docker image building, improving Docker image building efficiency and increasing Docker image building success rate.

[0034] 2. This invention supports the creation or import of Dockerfile configuration files, so it can be applied to both newly created Dockerfile configuration files and existing Dockerfile configuration files, and has the advantage of good versatility. Attached Figure Description

[0035] Figure 1 This is a schematic diagram of the basic process of the method in an embodiment of the present invention.

[0036] Figure 2This is a flowchart of the horizontal search in an embodiment of the present invention.

[0037] Figure 3 This is a flowchart of the vertical search in an embodiment of the present invention.

[0038] Figure 4 This is a flowchart illustrating the import of a Dockerfile configuration file in an embodiment of the present invention.

[0039] Figure 5 This is a schematic diagram illustrating the principle of parsing lines in the Dockerfile configuration file in an embodiment of the present invention.

[0040] Figure 6 This is a schematic diagram of the control structure corresponding to each row in the graphical interface of this invention.

[0041] Figure 7 This is a flowchart illustrating the creation of a Dockerfile configuration file in an embodiment of the present invention. Detailed Implementation

[0042] like Figure 1 As shown in the main flow on the left, this embodiment provides a method for quickly building Docker images, including:

[0043] S101, Create or import the Dockerfile configuration file;

[0044] S102, perform automatic dependency environment completion for the binary program imported by the user in the Dockerfile configuration file. The dependency environment includes the base image information of the Dockerfile configuration file and the dependency package information of the binary program.

[0045] S103 builds a Docker image based on a Dockerfile configuration file that has completed dependency auto-completion.

[0046] like Figure 1 As shown in the sub-process on the right, step S102 of this embodiment includes:

[0047] S201, perform a horizontal search to determine the base image information, and perform a vertical search to obtain the dependency package information of the binary program;

[0048] S202 writes the base image information and the dependency package information of the binary program into the Dockerfile configuration file.

[0049] This embodiment determines the base image information by performing a horizontal search and obtains the dependency package information of the binary program by performing a vertical search. It realizes a grid-like search process that automatically completes the dependency environment of the binary program imported by the user in the Dockerfile configuration file. This allows for the orderly completion of the base image information in the Dockerfile configuration file and the dependency package information of the binary program, enabling rapid Docker image building, improving Docker image building efficiency, and increasing the success rate of Docker image building.

[0050] like Figure 2 As shown, in step S201 of this embodiment, the horizontal search to determine the base image information includes:

[0051] S301, Determine the name of the Docker image to be built and initialize the dependency environment variables;

[0052] S302, calculate the image name of the Docker image to be built and the first overlap m of the image in the remote repository. If the maximum value of the first overlap m is greater than a set value, then assign the image in the remote repository corresponding to the maximum value of the first overlap m as the base image of the Docker image to be built to the dependent environment variables; calculate the image name of the Docker image and the second overlap n of the local image. If the maximum value of the second overlap n is greater than a set value, then assign the local image corresponding to the maximum value of the second overlap n as the base image of the Docker image to be built to the dependent environment variables; otherwise, automatically build the base image according to the image name of the Docker image to be built, store it locally, and assign the automatically built base image to the dependent environment variables.

[0053] S303 outputs the image information determined by the lateral search, which depends on the environment variables.

[0054] It should be noted that the first overlap degree *m* and the second overlap degree *n* are methods for calculating the overlap of string pairs, which are common string matching methods. Therefore, their specific calculation details will not be elaborated here. The values ​​of *m* and *n* will be automatically matched according to the actual system. The value of *m* is affected by the overlap between the platform-related image name and the images in the repository. Similarly, the value of *n* is affected by the overlap between the platform-related image name and the local image. When the values ​​of *m* and *n* are small, if there is no existing base image that meets the requirements for building an image for this language, a self-made local image will be started, thereby completing the base image information. Compared with the traditional method of generating Docker images, it is not necessary to accurately input the base image information, thus improving the efficiency and success rate of Docker image building.

[0055] like Figure 3As shown, in step S201 of this embodiment, the vertical search to obtain the dependency package information of the binary program includes:

[0056] S401, Initialize the dependency package path array used to record the dependency package paths of the binary program;

[0057] S402 iterates through the binary program in the Dockerfile configuration file by calling the binary dependency query command to obtain the dependency packages that the binary program depends on and the dependency packages that the dependency packages depend on. After deduplicating the dependency packages in the dependency package set, it matches them with the program packages in the software source and writes the paths of the matched program packages into the dependency package path array.

[0058] S403 outputs the dependency package information of the binary program by using the dependency package path array as a vertical search.

[0059] As an optional implementation, in step S402 of this embodiment, when obtaining the dependency packages that the binary program depends on and the dependency packages that the dependency packages depend on, the binary dependency query command is encapsulated in a recursive function. By directly calling the recursive function with the dependency packages that the binary program depends on, the recursive function can recursively call itself according to the obtained dependency packages that the binary program depends on, thereby obtaining the dependency packages that the binary program depends on and the dependency packages that the dependency packages depend on.

[0060] As an optional implementation, in step S402 of this embodiment, when deduplicating the dependency packages in the dependency package set, considering that the path of the dependency package is relatively long, the dependency package is deduplicated by using a preset string verification function (such as MD5) to calculate the verification value of the dependency package, and then by checking whether the verification values ​​are the same.

[0061] like Figure 4 As shown, the import of the Dockerfile configuration file in step S101 of this embodiment includes:

[0062] S501 reads the imported Dockerfile configuration file;

[0063] S502, the lines of the Dockerfile configuration file are parsed to obtain the parsing results. The parsing results include the line type, which includes command line and comment lines. When the line type is command line, the parsing results also include the first string and the subsequent operation content string.

[0064] S503: Add the parsed results of the Dockerfile configuration file to the controls in the graphical interface in the original line order so that the user can modify them. If the user confirms that the modification is complete, proceed to step S102.

[0065] The above method enables the import of Dockerfile configuration files into the graphical interface, allowing users to modify or confirm the imported Dockerfile configuration files within the graphical interface.

[0066] like Figure 5 As shown, step S502 in this embodiment includes: initializing and establishing a decomposition task pool; mapping each line in the Dockerfile configuration file to a decomposition task in the decomposition task pool, and using the decomposition task to parse the content of the line to obtain the parsing result; waiting for the parsing results of all lines until all lines of the Dockerfile configuration file have been parsed, and then jumping to step S503. Through the decomposition tasks in the decomposition task pool, parallel processing of each line in the Dockerfile configuration file can be achieved, thereby improving the parsing efficiency of each line in the Dockerfile configuration file. Moreover, by waiting for the parsing results of all lines until all lines of the Dockerfile configuration file have been parsed, step S503 can prevent the parallel parsing results from being out of order, leading to incorrect analysis results.

[0067] like Figure 6 As shown, in step S503 of this embodiment, when the parsed result of the Dockerfile configuration file is added to the controls of the graphical interface according to the original line order, the corresponding control for each line includes two sets of fields: line type and line content. The line type is a selection control. When the line type is a comment line, the line content is a single edit control to display the comment content. When the line type is a command line, the line content includes two controls: the first string and the operation content string. The first string is a selection control and is bundled with a preset set of keywords from the Dockerfile configuration file for selection. Through this method, editing of both line types can be conveniently achieved in the graphical interface, helping developers quickly build images.

[0068] like Figure 7 As shown, step S101 of this embodiment, creating the Dockerfile configuration file includes:

[0069] S601, detect the user's operation. If the user confirms that a new row has been added, proceed to step S602; if the user confirms that the modification is complete, proceed to step S603.

[0070] S602, Display the selection control for the line type. If the user selects the line type as a comment line, display the editing control corresponding to the comment content for the user to enter the comment content; if the user selects the line type as a command line, display two controls, the first string and the operation content string, for the user to select the first string and enter the operation content string; jump to step S601;

[0071] S603, perform at least one check on the content of each newly added row, including non-empty check. If the check passes, it is determined that the user has confirmed the modification is complete, and the process jumps to step S102; otherwise, a check failure prompt is issued, and the process jumps to step S601.

[0072] The above method allows for easy editing and input of both types of lines when creating Dockerfile configuration files in a graphical interface, helping developers quickly build images.

[0073] In this embodiment, before building the Docker image in step S103, it also includes checking whether Docker is installed on the operating system. If Docker is installed, the process jumps to S101; if Docker is not installed, the process exits and prompts the user to install Docker. This avoids the situation where the method of this embodiment fails to build the Docker image in step S103 based on the Dockerfile configuration file with autocomplete dependencies when executing the method on a machine without Docker installed.

[0074] In summary, this embodiment of the Docker image rapid build method provides a fast image build process. To address the cumbersome Docker image build process and lack of a bootstrapping mechanism, it offers a rapid Docker image build process to help developers quickly build images. It also provides a graphical Dockerfile editing page and automatic dependency environment building functionality within the container. Furthermore, this embodiment of the Docker image rapid build method provides a fast parsing function for existing Dockerfile files, displaying the parsed content on the page. This not only quickly converts the Dockerfile into a graphical representation but also resolves image build failures caused by typos or formatting errors in the file. Based on the completed Dockerfile configuration file editing or import, this embodiment can automatically complete the dependency environment for the user-imported binary program in the Dockerfile configuration file. The dependency environment includes the base image information in the Dockerfile configuration file and the dependency package information of the binary program. The Docker image is then built based on the Dockerfile configuration file with automatically completed dependency environment, thereby achieving rapid Docker image build, improving Docker image build efficiency, and increasing the success rate of Docker image builds.

[0075] Furthermore, this embodiment also provides a Docker image rapid building system, including a microprocessor and a memory interconnected, wherein the microprocessor is programmed or configured to execute the aforementioned Docker image rapid building method. Additionally, this embodiment also provides a computer-readable storage medium storing a computer program for being programmed or configured by the microprocessor to execute the aforementioned Docker image rapid building method.

[0076] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0077] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should also be considered within the scope of protection of the present invention.

Claims

1. A method for rapidly building Docker images, characterized in that, include: S101, Create or import the Dockerfile configuration file; S102, perform automatic dependency environment completion for the binary program imported by the user in the Dockerfile configuration file. The dependency environment includes the base image information of the Dockerfile configuration file and the dependency package information of the binary program. S103, builds a Docker image based on the Dockerfile configuration file with auto-completion of dependencies; Step S102 includes: S201, perform a horizontal search to determine the base image information, and perform a vertical search to obtain the dependency package information of the binary program; S202, writes the base image information and the dependency package information of the binary program into the Dockerfile configuration file; The horizontal search to determine the base image information in step S201 includes: S301, Determine the name of the Docker image to be built and initialize the dependency environment variables; S302, calculate the image name of the Docker image to be built and the first overlap m of the image in the remote repository. If the maximum value of the first overlap m is greater than a set value, then assign the image in the remote repository corresponding to the maximum value of the first overlap m as the base image of the Docker image to be built to the dependent environment variables; calculate the image name of the Docker image and the second overlap n of the local image. If the maximum value of the second overlap n is greater than a set value, then assign the local image corresponding to the maximum value of the second overlap n as the base image of the Docker image to be built to the dependent environment variables; otherwise, automatically build the base image according to the image name of the Docker image to be built, store it locally, and assign the automatically built base image to the dependent environment variables. S303 outputs the dependent environment variables as the basic image information determined by the lateral search. Step S201 involves a vertical search to obtain the dependency package information of the binary program, including: S401, Initialize the dependency package path array used to record the dependency package paths of the binary program; S402, for the binary program in the Dockerfile configuration file, iteratively calls the binary dependency query command to obtain the dependency package that the binary program depends on and the dependency package that the dependency package depends on. After deduplicating the dependency packages in the dependency package set, it matches them with the program packages in the software source and writes the paths of the matched program packages into the dependency package path array. S403 outputs the dependency package information of the binary program by using the dependency package path array as a vertical search.

2. The method for rapidly building Docker images according to claim 1, characterized in that, Step S101, which imports the Dockerfile configuration file, includes: S501 reads the imported Dockerfile configuration file; S502, the lines of the Dockerfile configuration file are parsed to obtain the parsing results. The parsing results include the line type, which includes command line and comment lines. When the line type is command line, the parsing results also include the first string and the subsequent operation content string. S503: Add the parsed results of the Dockerfile configuration file to the controls in the graphical interface in the original line order so that the user can modify them. If the user confirms that the modification is complete, proceed to step S102.

3. The method for rapid Docker image building according to claim 2, characterized in that, Step S502 includes: initializing and establishing a decomposition task pool; mapping each line in the Dockerfile configuration file to a decomposition task in the decomposition task pool, and using the decomposition task to parse the content of the line to obtain the parsing result; waiting for the parsing results of all lines until all lines in the Dockerfile configuration file have been parsed, and then jumping to step S503.

4. The method for rapidly building Docker images according to claim 3, characterized in that, In step S503, when the parsed result of the Dockerfile configuration file is added to the controls of the graphical interface in the original line order, the corresponding control for each line includes two sets of fields: line type and line content. The line type is a selection control. When the line type is a comment line, the line content is a single edit control to display the comment content. When the line type is a command line, the line content includes two controls: the first string and the operation content string. The first string is a selection control and is bound to a preset set of keywords from the Dockerfile configuration file for selection.

5. The method for rapid Docker image building according to claim 1, characterized in that, Step S101, which involves creating the Dockerfile configuration file, includes: S601, Detect the user's operation. If the user confirms that a new row has been added, proceed to step S602; if the user confirms that the modification is complete, proceed to step S603. S602, Display the selection control for the line type. If the user selects the line type as a comment line, display the editing control corresponding to the comment content for the user to enter the comment content; if the user selects the line type as a command line, display two controls for the first string and the operation content string for the user to select the first string and enter the operation content string; jump to step S601; S603, perform at least one check on the content of each newly added row, including non-empty check. If the check passes, proceed to step S102; otherwise, issue a check failure prompt and proceed to step S601.

6. A Docker image rapid building system, comprising interconnected microprocessors and memory, characterized in that, The microprocessor is programmed or configured to execute the Docker image rapid build method according to any one of claims 1 to 5.

7. A computer-readable storage medium storing a computer program, characterized in that, The computer program is used to be programmed or configured by a microprocessor to execute the Docker image rapid build method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Dockerfile basic mirror image version information automatic completion method and device

    CN110221900A

  • Intelligent packaging method for automatically generating container mirror image according to application package characteristics

    CN110704098A

  • Method, device and equipment for container mirror image construction, and storage medium

    CN111190687A