A Dockerfile inference method, device, equipment and medium
By parsing the content of the Docker image layer, it predicts the Dockerfile instruction mode and generates the target Dockerfile, which solves the problems of opaque image construction, security risks and difficulty in updating caused by the lack of Dockerfile, and improves the security and development efficiency of the image.
Patent Information
- Application Number
- CN202410703812.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-03
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-06-03
AI Technical Summary
The absence or inaccessibility of the Dockerfile will lead to opacity in the image building process, increased security risks, difficulty in updating, and incompatibility of the image, affecting development efficiency and the security and reliability of the image.
By obtaining the contents of each image layer of the target Docker image, parsing and predicting the Dockerfile instruction pattern, and generating prediction instructions to infer the target Dockerfile, the inference efficiency and accuracy are improved.
Ensure the security and reliability of images, simplify the update process, quickly obtain stable images that meet specific needs, and reduce the workload of developers.
Smart Images

Figure CN118278526B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a Dockerfile inference method, device, equipment and medium. Background Art
[0002] As containerization technology becomes increasingly mature and widely used, the application container engine Docker has become the preferred tool for enterprises and developers to build, distribute and run applications. Dockerfile, as a key component of Docker image construction, plays a vital role.
[0003] However, in actual scenarios, Dockerfile is often missing or inaccessible, which not only increases the difficulty for developers to understand, optimize and maintain images, but also brings significant challenges in terms of Docker specificity, security and reliability. For example, the lack of Dockerfile will make it impossible for developers to clearly understand the image building process and potential security risks, and hidden malicious code or unauthorized software may have been included in the image; secondly, Dockerfile usually contains key setting information of the image running environment (such as user permissions, network configuration and security policies, etc.), and the lack of Dockerfile will make it impossible to accurately copy these setting information, which may lead to security vulnerabilities in the production environment; thirdly, when the application software version needs to be updated or the dependencies change, the update process will become extremely difficult if the Dockerfile is missing; at the same time, in the actual application process, developers often encounter a seemingly suitable Docker image, but because they cannot access the original Dockerfile, it is difficult for developers to determine whether this image is suitable for specific needs, so they have to spend a lot of time looking for other images or building new images from scratch.
[0004] However, in the prior art, for the above situation, developers usually build Dockerfile from scratch based on Docker's running information, which greatly increases the workload and reduces development efficiency. Summary of the invention
[0005] The present invention provides a Dockerfile inference method, device, equipment and medium, which can improve the inference efficiency of Dockerfile and the accuracy of inference results.
[0006] According to one aspect of the present invention, a Dockerfile inference method is provided, the method comprising:
[0007] Get the target Docker image and traverse the contents of each image layer corresponding to the target Docker image;
[0008] Parse the contents of each of the image layers, and predict the Dockerfile instruction pattern corresponding to the target Docker image based on the parsing results;
[0009] According to the Dockerfile instruction pattern, multiple predicted instructions corresponding to the target Docker image are generated, and according to the multiple predicted instructions, a target Dockerfile corresponding to the target Docker image is generated.
[0010] According to another aspect of the present invention, a Dockerfile inference device is provided, the device comprising:
[0011] The image layer traversal module is used to obtain the target Docker image and traverse the contents of each image layer corresponding to the target Docker image;
[0012] The image layer parsing module is used to parse the content in each of the image layers and predict the Dockerfile instruction mode corresponding to the target Docker image based on the parsing result;
[0013] The instruction prediction module is used to generate multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, and generate a target Dockerfile corresponding to the target Docker image according to the multiple predicted instructions.
[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Dockerfile inference method described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Dockerfile inference method described in any embodiment of the present invention when executed.
[0019] The technical solution provided by the embodiment of the present invention obtains the target Docker image and traverses the contents of each image layer of the target Docker image; parses the contents in each image layer and predicts the Dockerfile instruction mode corresponding to the target Docker image according to the parsing result; generates multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction mode. The technical means of generating the target Dockerfile according to the multiple predicted instructions can improve the inference efficiency of Dockerfile and the accuracy of the inference result, and help developers better understand and manage the image according to the inference result to ensure the security and reliability of the image. At the same time, developers can also modify the Dockerfile according to the update requirements and quickly obtain a new Docker image that meets specific requirements and is stable and reliable.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 is a flowchart of a Dockerfile inference method provided according to an embodiment of the present invention;
[0023] Figure 2 is a flowchart of another Dockerfile inference method provided according to an embodiment of the present invention;
[0024] Figure 3 is a flowchart of another Dockerfile inference method provided according to an embodiment of the present invention;
[0025] Figure 4 is a structural schematic diagram of a Dockerfile inference device provided according to an embodiment of the present invention;
[0026] Figure 5 It is a structural schematic diagram of an electronic device for implementing the Dockerfile inference method of an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme 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 only 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 ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention 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 data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Figure 1 The flowchart of a Dockerfile inference method provided by an embodiment of the present invention is applicable to inferring a Dockerfile for building a Docker image. The method can be executed by a Dockerfile inference device, which can be implemented in the form of hardware and / or software. The Dockerfile inference device can be configured in an electronic device. Figure 1 As shown, the method includes:
[0030] Step 110: Get the target Docker image, and traverse the contents of each image layer corresponding to the target Docker image.
[0031] In this embodiment, the target Docker image can be a Docker image whose corresponding original Dockerfile is missing or inaccessible to the original Dockerfile. Optionally, the target Docker image can be obtained from a Docker image repository or a storage location corresponding to the Docker image.
[0032] In this step, after obtaining the target Docker image, each image layer corresponding to the target Docker image can be traversed. The image layer refers to the set of file system changes formed by each step of the operation when building the target Docker image. Each image layer contains the file system change information that occurs during the construction of the target Docker image, such as file addition information, modification information, or deletion information.
[0033] Step 120: parse the content in each of the image layers, and predict the Dockerfile instruction pattern corresponding to the target Docker image based on the parsing result.
[0034] In this embodiment, optionally, the content (including files, directories, etc.) in each of the image layers can be parsed, and the application scenarios and application requirements satisfied by the target Docker image can be determined based on the parsing results. Then, based on the application scenarios and application requirements satisfied by the target Docker image, the Dockerfile instruction pattern corresponding to the target Docker image can be predicted.
[0035] The Dockerfile instruction mode can be understood as a fixed combination or combination of a series of Dockerfile instructions taken when building a Docker image under specific application scenarios and application requirements.
[0036] In a specific embodiment, taking the Docker image of a Web application as an example, the following Dockerfile instruction pattern is usually followed when building this Docker image: (a) Use the FROM instruction to specify a base image; (b) Use the WORKDIR instruction to set the working directory; (c) Use the COPY or ADD instruction to copy the application code to the image; (d) Use the RUN instruction to install dependencies and set the application environment; (e) Use the EXPOSE instruction to expose the port that the application needs to listen to; (f) Use the CMD or ENTRYPOINT instruction to set the command to be run when the container starts. In this instruction pattern, each step is determined according to the general requirements of building a Web application image, so it has a certain degree of universality and repeatability.
[0037] Correspondingly, assuming that the target Docker image in this embodiment meets the Web application requirements, it can be predicted that the Dockerfile instruction mode corresponding to the target Docker image is the above instruction mode.
[0038] Step 130: Generate multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, and generate a target Dockerfile corresponding to the target Docker image according to the multiple predicted instructions.
[0039] In this embodiment, optionally, after predicting the Dockerfile instruction pattern corresponding to the target Docker image, the Dockerfile instruction pattern can be adjusted according to the parsing results of each image layer (such as directory information, application code information, application environment information, and port information, etc.) to obtain multiple predicted instructions corresponding to the target Docker image.
[0040] In this step, specifically, after generating multiple prediction instructions, the multiple prediction instructions can also be optimized according to the actual configuration information of the target Docker image, such as adding environment variable setting information, working directory switching and other instructions to the prediction instructions, thereby generating the target Dockerfile.
[0041] The advantage of this setting is that it can ensure the integrity and availability of the target Dockerfile.
[0042] In this embodiment, a method of reversely inferring Dockerfile based on Docker image is proposed. Compared with the method of building Dockerfile from scratch in the prior art, since Dockerfile is generated based on the existing Docker image, the development efficiency, stability and reliability are higher; secondly, by parsing the content in each image layer, predicting the Dockerfile instruction pattern according to the parsing result, and generating Dockerfile according to the Dockerfile instruction pattern, the accuracy of the Dockerfile inference result can be improved.
[0043] The technical solution provided by the embodiment of the present invention obtains the target Docker image and traverses the contents of each image layer of the target Docker image; parses the contents in each image layer and predicts the Dockerfile instruction mode corresponding to the target Docker image according to the parsing result; generates multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction mode. The technical means of generating the target Dockerfile according to the multiple predicted instructions can improve the inference efficiency of Dockerfile and the accuracy of the inference result, and help developers better understand and manage the image according to the inference result to ensure the security and reliability of the image. At the same time, developers can also modify the Dockerfile according to the update requirements and quickly obtain a new Docker image that meets specific requirements and is stable and reliable.
[0044] Figure 2 A flowchart of another Dockerfile inference method provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the method includes:
[0045] Step 210: Get the target Docker image, and traverse the contents of each image layer corresponding to the target Docker image.
[0046] Step 220: Compare the contents in each of the image layers to obtain a difference analysis result between the image layers.
[0047] In this step, specifically, the content differences between the image layers can be compared to identify changed files or directories.
[0048] Step 230: determine the file type included in each of the image layers, and parse the metadata and configuration files in each of the image layers according to the file type to obtain a data parsing result.
[0049] In this step, specifically, the files included in each of the image layers can be classified to obtain the file type corresponding to each file (such as text file, binary file, image file, etc.), and then the metadata and configuration files in each image layer can be parsed according to different parsing methods corresponding to different file types to obtain data parsing results, which include detailed build information and operation information of the target Docker image.
[0050] Step 240: predict the Dockerfile instruction pattern corresponding to the target Docker image based on the difference analysis result and the data parsing result.
[0051] In this step, optionally, the application scenario and application requirements satisfied by the target Docker image can be determined based on the difference analysis results between the image layers and the data parsing results, and then the Dockerfile instruction mode corresponding to the target Docker image can be predicted based on the application scenario and application requirements.
[0052] In a specific embodiment, assume that the following difference analysis results and data parsing results appear in the image layers of the target Docker image: (a) in one layer, a Python script file named app.py is added; (b) in another layer, a Python library named flask is installed; (c) in the last layer, the environment variable FLASK_APP=app.py is set and port 5000 is exposed.
[0053] Based on the image layer change information reflected in the above results, we can determine the target Docker image's build process, file system change information, and data update information in a specific application scenario. Then, based on this information, we can predict the Dockerfile instruction pattern that may be used to build the target Docker image:
[0054] # Use a base Python image of version 3.6;
[0055] FROM python:3.6;
[0056] #Copy the local app.py file to the / app directory of the image;
[0057] COPY app.py / app / ;
[0058] # Run the command in the image to install the flask library;
[0059] RUN pip install flask;
[0060] # Set environment variables;
[0061] ENV FLASK_APP=app.py;
[0062] # Expose port 5000;
[0063] EXPOSE 5000.
[0064] Step 250: Obtain multiple historical Dockerfile inference cases, and based on the success rate of each of the historical Dockerfile inference cases, filter out candidate Dockerfile instructions whose occurrence frequency meets a preset frequency threshold and whose success rate is greater than a preset probability.
[0065] In one implementation of the present embodiment, based on the success rate of each of the historical Dockerfile inference cases, screening the alternative Dockerfile instructions whose occurrence frequency meets the preset frequency threshold and whose success rate is greater than a preset probability includes: obtaining the evaluation index corresponding to each instruction in each of the historical Dockerfile inference cases; wherein the evaluation index includes the usage frequency of each instruction, the security index and the storage capacity of the corresponding Docker image; based on the evaluation index corresponding to each instruction and the success rate of each of the historical Dockerfile inference cases, screening the alternative Dockerfile instructions whose occurrence frequency meets the preset frequency threshold and whose success rate is greater than a preset probability.
[0066] In this embodiment, the frequency of use of an instruction refers to the frequency at which the instruction appears in each historical Dockerfile inference case. The reason for evaluating the frequency of use of an instruction is that instructions that are used frequently may be more reliable. By evaluating the frequency of use of an instruction, a candidate Dockerfile instruction with a verified high reliability can be obtained.
[0067] The security index of an instruction is used to characterize the possibility of a security vulnerability in an instruction. Specifically, the security of the case can be inferred based on each historical Dockerfile, and the security index of each instruction can be counted, thereby screening out safer alternative Dockerfile instructions.
[0068] The storage capacity of the Docker image corresponding to the instruction refers to the storage capacity occupied by the Docker image generated according to the instruction. Some instructions may cause the image to be too large and affect the performance of the container. By evaluating the storage capacity of the Docker image corresponding to the instruction, you can filter out alternative Dockerfile instructions that will not cause the image to be too large, thereby avoiding affecting the performance of the container.
[0069] In a specific embodiment, if the following instruction is displayed in a historical Dockerfile inference case: RUN yumupdate && yum install -y package-name, and this instruction frequently appears in multiple historical Dockerfile inference cases and the success rate of each inference case is very high, then this instruction can be used as an alternative Dockerfile instruction in the image layer installation software package scenario.
[0070] Among them, yum stands for the package manager of the Linux operating system. Yum provides commands to find, install, and delete a certain package, a group of packages, or even all packages. The above instructions can be interpreted as: update the yum package manager to the latest version and install the software named package-name.
[0071] Step 260: Generate multiple predicted instructions corresponding to the target Docker image according to the candidate Dockerfile instructions and the Dockerfile instruction mode.
[0072] In this step, specifically, the candidate Dockerfile instructions may be combined with the Dockerfile instruction pattern to obtain multiple predicted instructions corresponding to the target Docker image.
[0073] Step 270: Generate a target Dockerfile corresponding to the target Docker image according to the multiple predicted instructions.
[0074] The technical solution provided by the embodiment of the present invention obtains the target Docker image, traverses the contents of each image layer corresponding to the target Docker image, compares the contents of each image layer to obtain a difference analysis result, determines the file type included in each image layer, parses the metadata and configuration files in each image layer according to the file type to obtain a data parsing result, predicts the Dockerfile instruction pattern according to the difference analysis result and the data parsing result, obtains multiple historical Dockerfile inference cases, screens alternative Dockerfile instructions according to the success rate of each historical Dockerfile inference case, generates multiple predicted instructions corresponding to the target Docker image according to the alternative Dockerfile instructions and the Dockerfile instruction pattern, and generates the target Dockerfile according to the multiple predicted instructions. The technical means can improve the inference efficiency of Dockerfile and the effectiveness of the inference result.
[0075] Figure 3 A flowchart of another Dockerfile inference method provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown, the method includes:
[0076] Step 310: Get the target Docker image, and traverse the contents of each image layer corresponding to the target Docker image.
[0077] Step 320: parse the content in each of the image layers, and predict the Dockerfile instruction pattern corresponding to the target Docker image based on the parsing result.
[0078] Step 330: Generate multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern.
[0079] Step 340: Determine the data dependency relationship between the image layers according to the content in the image layers.
[0080] In this step, specifically, the data dependency relationship between the image layers can be determined according to the calling relationship between the contents in each image layer.
[0081] Step 350: Sort the multiple predicted instructions according to the data dependency, and generate a target Dockerfile corresponding to the target Docker image according to the sorted multiple predicted instructions.
[0082] The advantage of this setting is that by sorting multiple predicted instructions according to the data dependencies between the image layers, the logical coherence of the target Dockerfile can be ensured, thereby improving the effectiveness of the target Dockerfile.
[0083] Step 360: Verify the target Dockerfile. If the verification of the target Dockerfile succeeds, store the target Dockerfile in a preset storage location so that the user can use the target Dockerfile according to the storage location.
[0084] In this step, specifically, if the target Dockerfile fails to be verified, the instructions in the target Dockerfile may be optimized and adjusted to obtain a new Dockerfile, and then the new Dockerfile may be verified until the verification succeeds.
[0085] In one implementation of this embodiment, verifying the target Dockerfile includes: generating a reference Docker image according to multiple instructions in the target Dockerfile; comparing the reference Docker image with the target Docker image, and determining a verification result of the target Dockerfile according to the comparison result.
[0086] In a specific embodiment, a Docker image (ie, a reference Docker image) can be generated according to multiple instructions in the target Dockerfile. If the reference Docker image can run normally and its performance is close to or consistent with that of the target Docker image, it can be determined that the target Dockerfile has been successfully verified.
[0087] The technical solution provided by the embodiment of the present invention obtains the target Docker image, traverses the contents in each image layer corresponding to the target Docker image, parses the contents in each image layer, and predicts the Dockerfile instruction pattern according to the parsing result, generates multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, determines the data dependency relationship between each image layer according to the content in each image layer, sorts the multiple predicted instructions according to the data dependency relationship, generates the target Dockerfile according to the sorted multiple predicted instructions, verifies the target Dockerfile, and if the target Dockerfile is successfully verified, stores the target Dockerfile in a preset storage location. This technical solution can improve the inference efficiency of Dockerfile and the effectiveness of the inference result.
[0088] Figure 4 A schematic diagram of the structure of a Dockerfile inference device provided in an embodiment of the present invention, wherein the device is applied to an electronic device, such as Figure 4As shown, the device includes: an image layer traversal module 410, an image layer parsing module 420 and an instruction prediction module 430.
[0089] The image layer traversal module 410 is used to obtain the target Docker image and traverse the contents of each image layer corresponding to the target Docker image;
[0090] The image layer parsing module 420 is used to parse the content in each of the image layers and predict the Dockerfile instruction mode corresponding to the target Docker image according to the parsing result;
[0091] The instruction prediction module 430 is used to generate a plurality of predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, and generate a target Dockerfile corresponding to the target Docker image according to the plurality of predicted instructions.
[0092] The technical solution provided by the embodiment of the present invention obtains the target Docker image and traverses the contents of each image layer of the target Docker image; parses the contents in each image layer and predicts the Dockerfile instruction mode corresponding to the target Docker image according to the parsing result; generates multiple predicted instructions corresponding to the target Docker image according to the Dockerfile instruction mode. The technical means of generating the target Dockerfile according to the multiple predicted instructions can improve the inference efficiency of Dockerfile and the accuracy of the inference result, and help developers better understand and manage the image according to the inference result to ensure the security and reliability of the image. At the same time, developers can also modify the Dockerfile according to the update requirements and quickly obtain a new Docker image that meets specific requirements and is stable and reliable.
[0093] Based on the above embodiment, the image layer parsing module 420 includes:
[0094] A difference analysis unit, used to compare the contents in each of the image layers to obtain a difference analysis result between the image layers;
[0095] A data parsing unit, used to determine the file type included in each of the image layers, and parse the metadata and configuration files in each of the image layers according to the file type to obtain a data parsing result;
[0096] The instruction pattern prediction unit is used to predict the Dockerfile instruction pattern corresponding to the target Docker image according to the difference analysis result and the data parsing result.
[0097] The instruction prediction module 430 includes:
[0098] An instruction screening unit is used to obtain multiple historical Dockerfile inference cases, and screen candidate Dockerfile instructions whose occurrence frequency meets a preset frequency threshold and whose success rate is greater than a preset probability according to the success rate of each of the historical Dockerfile inference cases;
[0099] An instruction processing unit, configured to generate a plurality of predicted instructions corresponding to a target Docker image according to the candidate Dockerfile instructions and the Dockerfile instruction pattern;
[0100] A historical data evaluation unit, used to obtain an evaluation index corresponding to each instruction in each of the historical Dockerfile inference cases; wherein the evaluation index includes the usage frequency, safety index and storage capacity of the corresponding Docker image of each instruction;
[0101] A historical data analysis unit, configured to screen candidate Dockerfile instructions whose occurrence frequency meets a preset frequency threshold and whose success rate is greater than a preset probability according to the evaluation index corresponding to each instruction and the success rate of each historical Dockerfile inference case;
[0102] A dependency determination unit, configured to determine the data dependency between the image layers according to the contents in the image layers;
[0103] An instruction sorting unit, configured to sort the plurality of predicted instructions according to the data dependency, and generate a target Dockerfile corresponding to the target Docker image according to the sorted plurality of predicted instructions;
[0104] A verification unit, configured to verify the target Dockerfile; if the verification of the target Dockerfile succeeds, the target Dockerfile is stored in a preset storage location, so that the user can use the target Dockerfile according to the storage location;
[0105] A reference image generation unit, configured to generate a reference Docker image according to a plurality of instructions in the target Dockerfile;
[0106] The image comparison unit is used to compare the reference Docker image with the target Docker image, and determine the verification result of the target Dockerfile according to the comparison result.
[0107] The above device can execute the methods provided by all the above embodiments of the present invention, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not fully described in the embodiments of the present invention, please refer to the methods provided by all the above embodiments of the present invention.
[0108] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0109] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0110] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0111] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the Dockerfile inference method.
[0112] In some embodiments, the Dockerfile inference method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the Dockerfile inference method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the Dockerfile inference method in any other appropriate manner (e.g., by means of firmware).
[0113] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0114] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0115] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0116] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0117] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0118] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0119] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0120] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A Dockerfile inference method, It is characterized in that The method comprises: Get the target Docker image and traverse the contents of each image layer corresponding to the target Docker image; Parse the contents of each of the image layers, and predict the Dockerfile instruction pattern corresponding to the target Docker image based on the parsing results; Generate a plurality of predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, and generate a target Dockerfile corresponding to the target Docker image according to the plurality of predicted instructions; The parsing of the contents in each of the image layers includes: comparing the contents in each of the image layers to obtain difference analysis results between the image layers; determining the file types included in each of the image layers, and parsing the metadata and configuration files in each of the image layers according to the file types to obtain data parsing results; Predicting a Dockerfile instruction pattern corresponding to the target Docker image according to the parsing result includes: predicting a Dockerfile instruction pattern corresponding to the target Docker image according to the difference analysis result and the data parsing result.
2. The method according to claim 1, It is characterized in that According to the Dockerfile instruction pattern, multiple predicted instructions corresponding to the target Docker image are generated, including: Obtain multiple historical Dockerfile inference cases, and according to the success rate of each of the historical Dockerfile inference cases, filter out candidate Dockerfile instructions whose occurrence frequency meets a preset frequency threshold and whose success rate is greater than a preset probability; According to the candidate Dockerfile instructions and the Dockerfile instruction pattern, multiple predicted instructions corresponding to the target Docker image are generated.
3. The method according to claim 2, It is characterized in that According to the success rate of each of the historical Dockerfile inference cases, the candidate Dockerfile instructions whose occurrence frequency meets the preset frequency threshold and whose success rate is greater than the preset probability are screened, including: Obtain the evaluation index corresponding to each instruction in each of the historical Dockerfile inference cases; The evaluation indicators include the usage frequency of each instruction, the safety index and the storage capacity of the corresponding Docker image; According to the evaluation index corresponding to each instruction and the success rate of each historical Dockerfile inference case, the candidate Dockerfile instructions whose occurrence frequency meets the preset frequency threshold and whose success rate is greater than the preset probability are screened.
4. The method according to claim 1, It is characterized in that According to multiple predicted instructions, the target Dockerfile corresponding to the target Docker image is generated, including: Determine the data dependency relationship between the image layers according to the content in the image layers; The multiple predicted instructions are sorted according to the data dependency, and a target Dockerfile corresponding to the target Docker image is generated according to the sorted multiple predicted instructions.
5. The method according to claim 1, It is characterized in that After generating the target Dockerfile corresponding to the target Docker image, it also includes: Verify the target Dockerfile; If the target Dockerfile is successfully verified, the target Dockerfile is stored in a preset storage location, so that the user can use the target Dockerfile according to the storage location.
6. The method according to claim 5, It is characterized in that Verify the target Dockerfile, including: Generate a reference Docker image according to multiple instructions in the target Dockerfile; The reference Docker image is compared with the target Docker image, and a verification result of the target Dockerfile is determined according to the comparison result.
7. A Dockerfile inference device, It is characterized in that The device comprises: The image layer traversal module is used to obtain the target Docker image and traverse the contents of each image layer corresponding to the target Docker image; The image layer parsing module is used to parse the content in each of the image layers and predict the Dockerfile instruction mode corresponding to the target Docker image based on the parsing result; An instruction prediction module is used to generate a plurality of predicted instructions corresponding to the target Docker image according to the Dockerfile instruction pattern, and generate a target Dockerfile corresponding to the target Docker image according to the plurality of predicted instructions; The parsing of the contents in each of the image layers includes: comparing the contents in each of the image layers to obtain difference analysis results between the image layers; determining the file types included in each of the image layers, and parsing the metadata and configuration files in each of the image layers according to the file types to obtain data parsing results; Predicting a Dockerfile instruction pattern corresponding to the target Docker image according to the parsing result includes: predicting a Dockerfile instruction pattern corresponding to the target Docker image according to the difference analysis result and the data parsing result.
8. An electronic device, It is characterized in that The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Dockerfile inference method according to any one of claims 1 to 6.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Dockerfile inference method according to any one of claims 1 to 6 when executed.
