CN110908671A - Method and device for constructing docker mirror image and computer readable storage medium - Google Patents
Method and device for constructing docker mirror image and computer readable storage medium Download PDFInfo
- Publication number
- CN110908671A CN110908671A CN201811083312.8A CN201811083312A CN110908671A CN 110908671 A CN110908671 A CN 110908671A CN 201811083312 A CN201811083312 A CN 201811083312A CN 110908671 A CN110908671 A CN 110908671A
- Authority
- CN
- China
- Prior art keywords
- docker
- mirror image
- software
- image
- instruction
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/61—Installation
- G06F8/63—Image based installation; Cloning; Build to order
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The disclosure provides a method, a system and a device for constructing a docker mirror image and a computer readable storage medium, and relates to the technical field of computers. The method for constructing the docker mirror image comprises the following steps: searching a basic mirror image recorded by a dockerfile file in a distributed memory system; pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching a basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system; under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse; and executing the instruction recorded by the dockerfile file to construct the docker image depending on the basic image. The method and the device can shorten the construction time of the docker mirror image and improve the construction speed and the construction efficiency of the docker mirror image.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for constructing a docker image, and a computer-readable storage medium.
Background
Docker is an open source application container engine that allows developers to package applications and dependency packages into a portable container and then publish them on linux machines. Based on multiple open source technologies on the linux platform, the docker can provide an efficient, quick and lightweight container to manage the life cycle of encapsulation, distribution, deployment and operation of the application.
The Docker image (image) is a core concept of Docker, is a read-only template for starting a container, and is a root file system (root file system) required for starting the container. The docker mirror image is formed by overlapping a plurality of read-only layer file systems, and when a container is started, the docker can load the mirror image layer and add a writable layer on the mirror image layer. Any changes made on the container are recorded on the writable layer.
The construction of the Docker mirror image is mainly customized by writing a Dockerfile file, and a mirror image layer is added when a run instruction is run in the Dockerfile to generate a new mirror image file.
Disclosure of Invention
One technical problem solved by the present disclosure is how to increase the speed of constructing a docker image.
According to an aspect of the embodiments of the present disclosure, there is provided a method for constructing a docker image, including: searching a basic mirror image recorded by a dockerfile file in a distributed memory system; pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching a basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system; under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse; and executing the instruction recorded by the dockerfile file to construct the docker image depending on the basic image.
In some embodiments, the basic mirror image in the private warehouse is obtained by copying the basic mirror image with the frequency higher than the preset value in the docker public warehouse; the basic mirror image in the distributed memory system is obtained by copying the basic mirror image with N bits before the frequency ranking in the private warehouse, wherein N is the maximum quantity of the basic mirror images which can be stored in the distributed memory system.
In some embodiments, the method further comprises: extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
In some embodiments, the method further comprises: and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
In some embodiments, the method further comprises: extracting the software name of the target software installation instruction from the dockerfile file; querying a mapping relation between a predefined software name and a software function by using the software name, and determining the software function corresponding to the software name; and if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
In some embodiments, the method further comprises: in the dockerfile file, the instruction for deleting the software package is connected in series with the instruction for operating the software package by using the instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
In some embodiments, the method further comprises: determining software belonging to the same software function category by using a predefined software function classification table; using an instruction serial symbol to serially connect instructions of software with the same software function type operated by the dockerfile file to obtain a serial instruction; and executing the series instruction by using the same run instruction, so that the software with the same software function class is positioned in the same mirror image layer of the constructed docker mirror image.
In some embodiments, executing instructions recorded by a dockerfile file, constructing a docker image comprises: and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
In some embodiments, executing instructions recorded by a dockerfile file, constructing a docker image comprises: loading a filter file, wherein the filter file comprises files and directories which need to be excluded in the construction context directory; and when the context directory is constructed by packaging, removing the files and the directory according to the filter files.
According to an aspect of the embodiments of the present disclosure, there is provided an apparatus for constructing a docker image, including: a base mirror search module configured to: searching a basic mirror image recorded by a dockerfile file in a distributed memory system; a base mirror pull module configured to: pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching a basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system; under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse; a docker image construction module configured to: and executing the instruction recorded by the dockerfile file to construct the docker image depending on the basic image.
In some embodiments, the basic mirror image in the private warehouse is obtained by copying the basic mirror image with the frequency higher than the preset value in the docker public warehouse; the basic mirror image in the distributed memory system is obtained by copying the basic mirror image with N bits before the frequency ranking in the private warehouse, wherein N is the maximum quantity of the basic mirror images which can be stored in the distributed memory system.
In some embodiments, the apparatus further comprises a common instruction optimization module configured to: extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
In some embodiments, the apparatus further comprises a version number tagging module configured to: and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
In some embodiments, the apparatus further comprises an instruction deletion module configured to: extracting the software name of the target software installation instruction from the dockerfile file; querying a mapping relation between a predefined software name and a software function by using the software name, and determining the software function corresponding to the software name; and if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
In some embodiments, the apparatus further comprises a first instruction concatenation module configured to: in the dockerfile file, the instruction for deleting the software package is connected in series with the instruction for operating the software package by using the instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
In some embodiments, the apparatus further comprises a second instruction concatenation module configured to: determining software belonging to the same software function category by using a predefined software function classification table; using an instruction serial symbol to serially connect instructions of software with the same software function type operated by the dockerfile file to obtain a serial instruction; and executing the series instruction by using the same run instruction, so that the software with the same software function class is positioned in the same mirror image layer of the constructed docker mirror image.
In some embodiments, the docker image construction module is configured to: and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
In some embodiments, the docker image construction module is configured to: loading a filter file, wherein the filter file comprises files and directories which need to be excluded in the construction context directory; and when the context directory is constructed by packaging, removing the files and the directory according to the filter files.
According to another aspect of the embodiments of the present disclosure, there is provided an apparatus for constructing a docker image, including: a memory; and a processor coupled to the memory, the processor configured to perform the aforementioned method of constructing a docker image based on instructions stored in the memory.
According to still another aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, in which computer instructions are stored, and when executed by a processor, the instructions implement the foregoing method for constructing a docker image.
The method and the device can shorten the construction time of the docker mirror image and improve the construction speed and the construction efficiency of the docker mirror image.
Other features of the present disclosure and advantages thereof will become apparent from the following detailed description of exemplary embodiments thereof, which proceeds with reference to the accompanying drawings.
Drawings
In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only some embodiments of the present disclosure, and for those skilled in the art, other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 shows a schematic flow diagram of a method of constructing a docker image according to some embodiments of the present disclosure.
Fig. 2 shows a schematic structural diagram of an apparatus for constructing a docker image according to some embodiments of the present disclosure.
Fig. 3 shows a schematic structural diagram of an apparatus for constructing a docker image according to further embodiments of the present disclosure.
Fig. 4 shows a schematic structural diagram of an apparatus for constructing a docker image according to further embodiments of the present disclosure.
Detailed Description
The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, and not all of the embodiments. The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the disclosure, its application, or uses. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
The inventor researches and finds that the existing basic mirror needs to be reused when the docker mirror is constructed, so that the traditional method for constructing the docker mirror searches and pulls the basic mirror which needs to be relied on in the docker hub by default. The docker hub is a public warehouse maintained by docker officials, with existing base images stored. Since the docker hub belongs to a foreign website, the conventional method of constructing the docker image depends on the network speed and the network stability of accessing the docker hub. Meanwhile, the image with larger software size needs longer image pulling time. Due to the reasons, the construction time of the docker mirror image is long, the construction speed is slow, and the construction efficiency is low.
In view of the above problems, the present disclosure provides a method for constructing a docker mirror image, which can shorten the construction time of the docker mirror image and improve the construction speed and the construction efficiency of the docker mirror image.
Some embodiments of the disclosed method of constructing a docker image are first described in conjunction with fig. 1.
Fig. 1 shows a schematic flow diagram of a method of constructing a docker image according to some embodiments of the present disclosure. As shown in fig. 1, the present embodiment includes steps S102 to S110.
In step S102, a base image recorded by the dockerfile file is searched in the distributed memory system.
The basic mirror image in the distributed memory system is obtained by copying the basic mirror image with the first N bits (for example, the first 100 bits) of the pull frequency in the private warehouse, where N is the maximum number of the basic mirror images that can be stored in the distributed memory system. The base image in the private warehouse is obtained by copying the base image with the pulling frequency higher than a preset value (for example, higher than 5%) in the docker public warehouse (docker hub). Those skilled in the art will appreciate that since the pull frequency of the base image in the private vault is dynamically updated, and thus the base image in the distributed memory system is also dynamically updated, the base image of the LRU (least recently Used) in the distributed memory system is replaced and moved out of the distributed memory system.
Dockerfile is a configuration file in text format that a user can use to quickly build a custom image. Dockerfile is composed of a line of line command line statements, mainly including: basic mirror image information, maintainer information, mirror image operation instructions and container execution instructions when starting. Dockerfile describes the underlying mirror name on which to depend first, followed by the maintainer information, then the mirror operation instruction, (e.g., a run instruction, to execute the follow-up command on the mirror), and finally the cmd instruction (to specify the operation command when the container is run). Since the dockerfile will record the name of the dependent base image, the base image can be searched by the name of the dependent base image. And during searching, judging whether the basic mirror image exists in the distributed memory system. If yes, go to step S104; if not, go to step S106.
In step S104, the base image is pulled from the distributed memory system.
Distributed memory systems such as tacchyon may be used, for example. The speed of searching and pulling the mirror image from the distributed memory system is high (second level), the access to the distributed memory system is more stable than the access to a docker public warehouse or a private warehouse, the search time and the pulling time of the mirror image are greatly shortened, and the mirror image construction time is further shortened.
In step S106, the private repository is searched for a base image.
And during searching, judging whether the private warehouse stores the basic mirror image. If yes, go to step S108; if not, go to step S110.
In step S108, the base image is pulled from the private repository.
In step S110, the base image is pulled from the docker public warehouse.
In step S112, depending on the base image, an instruction described in the dockerfile file is executed, and a docker image is constructed.
For example, the docker daemon relies on the base image to parse the docker file layer by layer to build a new docker image.
In the above embodiment, the existing mirror image in the docker hub is pulled to the private warehouse in advance, and the existing mirror image with higher pulling frequency in the private warehouse is further pulled to the memory in advance. When the existing mirror images need to be reused, the existing mirror images are preferentially selected to be searched and pulled from the memory according to the set sequence, and the existing mirror images are secondarily selected to be searched and pulled from the private warehouse, so that the construction time of the docker mirror images is greatly shortened, and the construction speed and the construction efficiency of the docker mirror images are improved. Under the condition that a network is unstable when a docker hub is accessed, or under the condition that the software size of an existing image is large, the speed improvement effect of constructing the docker image is particularly remarkable.
In some embodiments, step S112 may include: and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
During the process of constructing the image, a large number of temporary files, installation files or temporary directories are generated, such as temporary files stored in a package manager or software source codes required to be installed in a dockerfile. The inventors have found that if these files or directories are left unprocessed, the size of the image is greatly increased. In view of this, before the completion of constructing each layer of docker image, the installation files in the/var/lib/apt/list/directory and the temporary files in the preset temporary file directory are automatically cleaned in time, so that the size of the image can be greatly reduced.
In some embodiments, step S112 further includes: loading a filter file, wherein the filter file comprises files and directories which need to be excluded in the construction context directory; and when the context directory is constructed by packaging, removing the files and the directory according to the filter files.
When a docker image is constructed, after a client initiates a construction instruction and transmits the construction instruction to a docker engine (daemon), the docker packages and transmits a specified construction context directory to the docker engine, and not all files in the construction context directory are used in the docker file. The packaging of files or directories which cannot be used seriously affects the performance of mirror image construction and reduces the speed of constructing the mirror image.
In view of this, the embodiment configures a filter file, where the filter file includes files and directories that need to be excluded in building the context directory. When the context directory is constructed in a packaging mode in the docker mirror image generation process, the docker engine loads the filter files and excludes files and directories (such as temporary directories, temporary files, readme files and the like) according to the filter files, so that packaged contents are simplified, the size of the constructed mirror image is reduced, and mirror image construction time is shortened.
The inventors have also found that the traditional method takes an additional amount of time to construct a docker image, and is also associated with inefficient execution of instructions in the dockerfile. The execution sequence and execution mode of the instructions in the Dockerfile not only affect the construction speed of the mirror image, but also affect the space occupied by the mirror image. Writing a high quality dockerfile file requires a highly experienced docker developer. Therefore, the inventor provides a dockerfile instruction optimization function, and performs the following optimization on the dockerfile instruction developed by a beginner.
Extracting a common instruction: extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
In the Dockerfile, many instructions in each code block are common, such as a digital authentication instruction, a file copy instruction, a directory creation instruction, and so on. The common instructions are extracted to be executed before the code blocks, and the repeated common instructions are deleted, so that the execution sequence and the execution mode of the instructions are optimized. The method provided by the embodiment can improve the instruction execution efficiency of the dockerfile file, reduce the time for constructing the docker image and reduce the size of the constructed image. In addition, the method provided by the embodiment is beneficial to maintaining the instructions of the dockerfile.
(II) solidifying the software version: and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
If the dockerfile file does not record the version number of the base image or software package, the docker defaults to processing with the latest image version or software version. The latest version of the base image or software package may delete some functions required to construct the docker image, thereby causing a failed construction. Even if the latest version of the base image or software package does not delete the functionality required to construct the docker image, it causes a dramatic expansion in the size of the constructed image, leading to a lot of uncertainty.
Marking the version number of the base image or software package recorded in the dockerfile, for example, using the version number of the software package as ubuntu16.04 or ubuntu14.04, etc., enables the image generated by the construction to occupy a relatively stable space, thereby reducing the size of the constructed image.
(III) simplifying software instructions: first, the software name of the target software installation instruction is extracted from the dockerfile file. And then, inquiring the mapping relation between the predefined software name and the software function by using the software name, and determining the software function corresponding to the software name. And if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
For example, the image is constructed by selecting and using the centros software, and the centros software is attached with SSH service and mysql database functions, that is, the centros in the mapping relation between the predefined software name and the software function corresponds to the SSH service and the mysql database function. Then, in subsequent software installation instructions in the dockerfile file, instructions relating to the ssh service or mysql database may be deleted and no separate installation of the ssh service or mysql database may be performed.
By simplifying the instruction, the software size of the constructed mirror image can be reduced, and the time for compiling and deploying the docker application is further shortened, so that the construction time of the docker mirror image is shortened, and the construction speed and the construction efficiency of the docker mirror image are improved.
And (IV) deleting the software package: in the dockerfile file, the instruction for deleting the software package is connected in series with the instruction for operating the software package by using the instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
When the mirror image is constructed, the installation package of the software is not used after the related instructions of the software are compiled. If the instruction of deleting the software package is executed independently, the software package cannot be deleted according to the layering principle of the docker image, so that the software for constructing the docker image is large in size.
In view of this, according to the dockerfile writing specification, instructions operating on the same software are usually located in the same code block. The instructions in this code block are scanned and concatenated together according to the original instruction order. The Docker engine executes other operation instructions on the software package at the same mirror image layer, and then executes the deleting instruction, so that the software package can be really deleted, the software size for constructing the mirror image is reduced, and the instruction maintenance is facilitated.
(V) merging mirror image levels: firstly, software belonging to the same software function category is determined by using a predefined software function classification table. And then, using the instruction serial symbol to serially connect the instructions of the software with the same software function type operated by the dockerfile file to obtain a serial instruction. And finally, executing the series instruction by adopting the same run instruction, so that the software with the same software function category is positioned in the same mirror image layer of the constructed docker mirror image.
When an image is constructed, an image layer is added every time a run instruction is added in the dockerfile. The maximum value of the mirror layer is 127, and the docker merges the mirror layers when the mirror layer exceeds 127 layers. Since the docker needs to compare each layer with the previous layer when merging the mirror layers, the more time it takes, and the very low efficiency of mirror image construction is achieved. Meanwhile, if too many run instructions exist in the dockerfile, for example, a simple copy instruction or a delete instruction may generate a mirror layer, and such docker mirror is difficult to reuse.
For this case, the inventors provide a function of mirror level merging. The operation instructions of the software with similar functions are connected in series and executed by the same run instruction. When the docker mirror image is constructed, the software can be fused in the same mirror image layer, so that the number of mirror image layers is reduced, the speed of constructing the mirror image is greatly improved, and the size of the mirror image is obviously reduced. The working performance of the docker engine can be improved, and the storage resources can be saved.
An apparatus for constructing a docker image according to some embodiments of the present disclosure is described below in conjunction with fig. 2.
Fig. 2 shows a schematic structural diagram of an apparatus for constructing a docker image according to some embodiments of the present disclosure. As shown in fig. 2, the apparatus 20 for constructing a docker image in the present embodiment includes:
a base image search module 202 configured to: searching a basic mirror image recorded by a dockerfile file in a distributed memory system; a base image pull module 204 configured to: pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching a basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system; under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse; a docker image construction module 206 configured to: and executing the instruction recorded by the dockerfile file to construct the docker image depending on the basic image.
In some embodiments, the basic mirror image in the private warehouse is obtained by copying the basic mirror image with the frequency higher than the preset value in the docker public warehouse; the basic mirror image in the distributed memory system is obtained by copying the basic mirror image with N bits before the frequency ranking in the private warehouse, wherein N is the maximum quantity of the basic mirror images which can be stored in the distributed memory system.
In some embodiments, docker image construction module 206 is configured to: and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
In some embodiments, docker image construction module 206 is configured to: loading a filter file, wherein the filter file comprises files and directories which need to be excluded in the construction context directory; and when the context directory is constructed by packaging, removing the files and the directory according to the filter files.
The apparatus for constructing a docker image according to further embodiments of the present disclosure is described below with reference to fig. 3.
Fig. 3 shows a schematic structural diagram of an apparatus for constructing a docker image according to further embodiments of the present disclosure.
In some embodiments, the apparatus 30 for constructing a docker image further comprises: a common instruction optimization module 3051 configured to: extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
In some embodiments, the apparatus 30 further includes a version number tagging module 3053 configured to: and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
In some embodiments, the apparatus 30 further comprises an instruction deletion module 3055 configured to: extracting the software name of the target software installation instruction from the dockerfile file; querying a mapping relation between a predefined software name and a software function by using the software name, and determining the software function corresponding to the software name; and if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
In some embodiments, the apparatus 30 further comprises a first instruction concatenation module 3057 configured to: in the dockerfile file, the instruction for deleting the software package is connected in series with the instruction for operating the software package by using the instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
In some embodiments, the apparatus 30 further comprises a second instruction concatenation module 3059 configured to: determining software belonging to the same software function category by using a predefined software function classification table; using an instruction serial symbol to serially connect instructions of software with the same software function type operated by the dockerfile file to obtain a serial instruction; and executing the series instruction by using the same run instruction, so that the software with the same software function class is positioned in the same mirror image layer of the constructed docker mirror image.
Fig. 4 shows a schematic structural diagram of an apparatus for constructing a docker image according to further embodiments of the present disclosure. As shown in fig. 4, the apparatus 40 for constructing a docker image of this embodiment includes: a memory 410 and a processor 420 coupled to the memory 410, the processor 420 configured to execute the method of constructing a docker image in any of the foregoing embodiments based on instructions stored in the memory 410.
The apparatus 40 for constructing a docker image may further include an input output interface 430, a network interface 440, a storage interface 450, and the like. These interfaces 430, 440, 450 and the connection between the memory 410 and the processor 420 may be, for example, via a bus 460. The input/output interface 430 provides a connection interface for input/output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 440 provides a connection interface for various networking devices. The storage interface 450 provides a connection interface for external storage devices such as an SD card and a usb disk.
The present disclosure also includes a computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the method of constructing a docker image in any of the foregoing embodiments.
As will be appreciated by one skilled in the art, embodiments of the present disclosure may be provided as a method, system, or computer program product. Accordingly, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product embodied on one or more computer-usable non-transitory storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present disclosure is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the disclosure. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may 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 means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
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 such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only exemplary of the present disclosure and is not intended to limit the present disclosure, so that any modification, equivalent replacement, or improvement made within the spirit and principle of the present disclosure should be included in the scope of the present disclosure.
Claims (20)
1. A method of constructing a docker image, comprising:
searching a basic mirror image recorded by a dockerfile file in a distributed memory system;
pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching the basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system;
under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse;
and executing the instruction recorded by the dockerfile file depending on the basic mirror image, and constructing the docker mirror image.
2. The method of claim 1, wherein,
the basic mirror image in the private warehouse is obtained by copying the basic mirror image with the frequency higher than the preset value in the docker public warehouse;
the basic mirror image in the distributed memory system is obtained by copying the basic mirror image with N bits before the frequency ranking in the private warehouse, wherein N is the maximum quantity of the basic mirror images which can be stored in the distributed memory system.
3. The method of claim 1, further comprising:
extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
4. The method of claim 1, further comprising:
and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
5. The method of claim 1, further comprising:
extracting the software name of the target software installation instruction from the dockerfile file;
querying a mapping relation between a predefined software name and a software function by using the software name, and determining the software function corresponding to the software name;
and if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
6. The method of claim 1, further comprising:
in the dockerfile file, the instruction for deleting the software package is connected in series to other instructions for operating the software package by using an instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
7. The method of claim 1, further comprising:
determining software belonging to the same software function category by using a predefined software function classification table;
using an instruction serial symbol to serially connect instructions of software with the same software function type operated by the dockerfile file to obtain a serial instruction;
and executing the series instruction by using the same run instruction, so that the software of the same software function class is positioned in the same mirror image layer of the constructed docker mirror image.
8. The method of claim 1, wherein the executing instructions recorded by the dockerfile file, constructing the docker image comprises:
and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
9. The method of claim 1, wherein the executing instructions recorded by the dockerfile file, constructing the docker image comprises:
loading a filter file, wherein the filter file comprises files and directories which need to be excluded in a construction context directory;
and when the context directory is constructed by packaging, the file and the directory are excluded according to the filter file.
10. An apparatus for constructing a docker image, comprising:
a base mirror search module configured to: searching a basic mirror image recorded by a dockerfile file in a distributed memory system;
a base mirror pull module configured to: pulling the basic mirror image from the distributed memory system under the condition that the basic mirror image is stored in the distributed memory system; searching the basic mirror image in a private warehouse under the condition that the basic mirror image is not stored in the distributed memory system; under the condition that the private warehouse stores the basic mirror image, pulling the basic mirror image from the private warehouse; under the condition that the private warehouse does not store the basic mirror image, pulling the basic mirror image from the docker public warehouse;
a docker image construction module configured to: and executing the instruction recorded by the dockerfile file depending on the basic mirror image, and constructing the docker mirror image.
11. The apparatus of claim 10, wherein,
the basic mirror image in the private warehouse is obtained by copying the basic mirror image with the frequency higher than the preset value in the docker public warehouse;
the basic mirror image in the distributed memory system is obtained by copying the basic mirror image with N bits before the frequency ranking in the private warehouse, wherein N is the maximum quantity of the basic mirror images which can be stored in the distributed memory system.
12. The apparatus of claim 10, the apparatus further comprising a common instruction optimization module configured to:
extracting the common instructions of all the code blocks in the dockerfile before all the code blocks, and deleting the repeated common instructions so that the docker engine preferentially executes the common instructions in the dockerfile and then executes the non-common instructions of all the code blocks in the dockerfile.
13. The apparatus of claim 10, the apparatus further comprising a version number tagging module configured to: and marking the version number of the basic image or the software package recorded by the docker file so that the docker engine can construct the docker image by using the basic image or the software package corresponding to the version number.
14. The apparatus of claim 10, the apparatus further comprising an instruction deletion module configured to:
extracting the software name of the target software installation instruction from the dockerfile file;
querying a mapping relation between a predefined software name and a software function by using the software name, and determining the software function corresponding to the software name;
and if other software installation instructions exist in the dockerfile file and the software names of the other software installation instructions correspond to the software functions, deleting the target software installation instruction.
15. The apparatus of claim 10, the apparatus further comprising a first instruction concatenation module configured to:
in the dockerfile file, the instruction for deleting the software package is connected in series to other instructions for operating the software package by using an instruction series connection symbol, so that the docker engine deletes the software package after executing other operations on the software package in the same mirror layer.
16. The apparatus of claim 10, the apparatus further comprising a second instruction concatenation module configured to:
determining software belonging to the same software function category by using a predefined software function classification table;
using an instruction serial symbol to serially connect instructions of software with the same software function type operated by the dockerfile file to obtain a serial instruction;
and executing the series instruction by using the same run instruction, so that the software of the same software function class is positioned in the same mirror image layer of the constructed docker mirror image.
17. The apparatus of claim 10, the docker image construction module configured to: and deleting the installation files and the temporary files in the preset file directory before the completion of constructing the docker image of each layer.
18. The method of claim 10, the docker image construction module configured to:
loading a filter file, wherein the filter file comprises files and directories which need to be excluded in a construction context directory;
and when the context directory is constructed by packaging, the file and the directory are excluded according to the filter file.
19. An apparatus for constructing a docker image, comprising:
a memory; and
a processor coupled to the memory, the processor configured to perform the method of constructing a docker image of any of claims 1-9 based on instructions stored in the memory.
20. A computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions which, when executed by a processor, implement the method of constructing a docker image according to any one of claims 1 to 9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811083312.8A CN110908671A (en) | 2018-09-18 | 2018-09-18 | Method and device for constructing docker mirror image and computer readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811083312.8A CN110908671A (en) | 2018-09-18 | 2018-09-18 | Method and device for constructing docker mirror image and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110908671A true CN110908671A (en) | 2020-03-24 |
Family
ID=69813122
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811083312.8A Pending CN110908671A (en) | 2018-09-18 | 2018-09-18 | Method and device for constructing docker mirror image and computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110908671A (en) |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111399865A (en) * | 2020-04-21 | 2020-07-10 | 贵州新致普惠信息技术有限公司 | Method for automatically constructing target file based on container technology |
CN111654533A (en) * | 2020-05-13 | 2020-09-11 | 国云科技股份有限公司 | Application automatic delivery system based on container environment |
CN111708610A (en) * | 2020-06-19 | 2020-09-25 | 北京神州泰岳软件股份有限公司 | Database client construction method and database operation method |
CN112612489A (en) * | 2020-12-16 | 2021-04-06 | 北京梆梆安全科技有限公司 | Software upgrade package construction method and device and electronic equipment |
CN113296873A (en) * | 2020-05-15 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Mirror image construction method and device, terminal equipment and computer storage medium |
CN113342359A (en) * | 2021-05-13 | 2021-09-03 | 烽火通信科技股份有限公司 | Intelligent generation method, device and equipment for container mirror image file and storage medium |
CN113495870A (en) * | 2020-04-01 | 2021-10-12 | 北京沃东天骏信息技术有限公司 | Mirror image construction method and device, electronic equipment and storage medium |
WO2021232289A1 (en) * | 2020-05-20 | 2021-11-25 | 深圳市欢太科技有限公司 | Image pulling method and related product |
CN115168905A (en) * | 2022-07-27 | 2022-10-11 | 中国电信股份有限公司 | Security detection method and device for mirror image construction file, medium and electronic equipment |
CN115454572A (en) * | 2022-09-20 | 2022-12-09 | 北京志凌海纳科技有限公司 | Method and system for constructing disk image of virtual machine based on Docker tool |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105740048A (en) * | 2016-01-26 | 2016-07-06 | 华为技术有限公司 | Image management method, device and system |
CN106790660A (en) * | 2017-01-18 | 2017-05-31 | 咪咕视讯科技有限公司 | A kind of dispositions method and device for realizing distributed memory system |
WO2017129106A1 (en) * | 2016-01-29 | 2017-08-03 | 腾讯科技(深圳)有限公司 | Data request processing method, server and system |
CN107066310A (en) * | 2017-03-11 | 2017-08-18 | 郑州云海信息技术有限公司 | It is a kind of to build and using the method and device in the privately owned warehouses of safe Docker |
WO2017166513A1 (en) * | 2016-03-31 | 2017-10-05 | 乐视控股(北京)有限公司 | Container technique-based method and system for application service seamless migration |
CN108052328A (en) * | 2017-11-09 | 2018-05-18 | 华中科技大学 | A kind of construction method of Android system and its application |
CN108170511A (en) * | 2017-12-26 | 2018-06-15 | 深信服科技股份有限公司 | A kind of docker mirror images acquisition methods, device, equipment and storage medium |
-
2018
- 2018-09-18 CN CN201811083312.8A patent/CN110908671A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105740048A (en) * | 2016-01-26 | 2016-07-06 | 华为技术有限公司 | Image management method, device and system |
WO2017129106A1 (en) * | 2016-01-29 | 2017-08-03 | 腾讯科技(深圳)有限公司 | Data request processing method, server and system |
WO2017166513A1 (en) * | 2016-03-31 | 2017-10-05 | 乐视控股(北京)有限公司 | Container technique-based method and system for application service seamless migration |
CN106790660A (en) * | 2017-01-18 | 2017-05-31 | 咪咕视讯科技有限公司 | A kind of dispositions method and device for realizing distributed memory system |
CN107066310A (en) * | 2017-03-11 | 2017-08-18 | 郑州云海信息技术有限公司 | It is a kind of to build and using the method and device in the privately owned warehouses of safe Docker |
CN108052328A (en) * | 2017-11-09 | 2018-05-18 | 华中科技大学 | A kind of construction method of Android system and its application |
CN108170511A (en) * | 2017-12-26 | 2018-06-15 | 深信服科技股份有限公司 | A kind of docker mirror images acquisition methods, device, equipment and storage medium |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113495870A (en) * | 2020-04-01 | 2021-10-12 | 北京沃东天骏信息技术有限公司 | Mirror image construction method and device, electronic equipment and storage medium |
CN111399865A (en) * | 2020-04-21 | 2020-07-10 | 贵州新致普惠信息技术有限公司 | Method for automatically constructing target file based on container technology |
CN111654533A (en) * | 2020-05-13 | 2020-09-11 | 国云科技股份有限公司 | Application automatic delivery system based on container environment |
CN113296873A (en) * | 2020-05-15 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Mirror image construction method and device, terminal equipment and computer storage medium |
WO2021232289A1 (en) * | 2020-05-20 | 2021-11-25 | 深圳市欢太科技有限公司 | Image pulling method and related product |
CN111708610A (en) * | 2020-06-19 | 2020-09-25 | 北京神州泰岳软件股份有限公司 | Database client construction method and database operation method |
CN111708610B (en) * | 2020-06-19 | 2024-02-27 | 北京神州泰岳软件股份有限公司 | Database client construction method and database operation method |
CN112612489A (en) * | 2020-12-16 | 2021-04-06 | 北京梆梆安全科技有限公司 | Software upgrade package construction method and device and electronic equipment |
CN112612489B (en) * | 2020-12-16 | 2024-03-12 | 北京梆梆安全科技有限公司 | Method and device for constructing upgrade package of software and electronic equipment |
CN113342359A (en) * | 2021-05-13 | 2021-09-03 | 烽火通信科技股份有限公司 | Intelligent generation method, device and equipment for container mirror image file and storage medium |
CN115168905A (en) * | 2022-07-27 | 2022-10-11 | 中国电信股份有限公司 | Security detection method and device for mirror image construction file, medium and electronic equipment |
CN115454572A (en) * | 2022-09-20 | 2022-12-09 | 北京志凌海纳科技有限公司 | Method and system for constructing disk image of virtual machine based on Docker tool |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110908671A (en) | Method and device for constructing docker mirror image and computer readable storage medium | |
US20190303120A1 (en) | Dynamic container deployment with parallel conditional layers | |
US9244717B2 (en) | Method and system for visualizing linked clone trees | |
US9639558B2 (en) | Image building | |
US8850423B2 (en) | Assisting server migration | |
US20120246645A1 (en) | Method for managing virtual machine, information processing apparatus, and medium for virtual machine management program | |
JP5886447B2 (en) | Location independent files | |
US20070276848A1 (en) | Apparatus and method for managing data | |
KR101355273B1 (en) | A computing system, a method for controlling thereof, and a computer-readable recording medium having a computer program for controlling thereof | |
US20120151198A1 (en) | System and Method for Instantiation of Distributed Applications from Disk Snapshots | |
US20080051921A1 (en) | Method for modifying configuration of business system | |
JP2013507668A (en) | File sharing system, file processing method, and program | |
JP7231518B2 (en) | Packaging support system and packaging support method | |
JPWO2017033441A1 (en) | System construction support system, method, and storage medium | |
JP6996629B2 (en) | Verification automation equipment, verification automation methods, and programs | |
US11226808B2 (en) | Application execution device, application execution method, and recording medium | |
KR101371619B1 (en) | Apparatus and method for componentizing legacy system | |
US20110107198A1 (en) | Information processing apparatus, storage medium, and information processing method | |
JP2022182577A (en) | Storage restore system, storage restore method, and storage restore program | |
CN104461612A (en) | Data processing method and device | |
JP7131119B2 (en) | Systems and methods for merging source data from a source application with target data in a target application | |
US20140282492A1 (en) | Information processing apparatus and information processing method | |
CN111045991B (en) | Implementation method for quickly opening file based on command line mode | |
CN115017161A (en) | Method, device and application for updating tree data structure by combining virtual DOM | |
CN117648198B (en) | Application adaptation method, device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |