Container reading and writing method and device, electronic equipment and storage medium
By establishing index information in the container image, the image level of the target object can be directly located for reading and writing, which solves the problem of low efficiency caused by searching layer by layer in the existing technology and realizes more efficient container read and write operations.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- LENOVO (BEIJING) LTD
- Filing Date
- 2022-01-17
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies are inefficient when reading and writing files in container images, requiring layer-by-layer searches, which leads to low efficiency.
By pre-establishing index information, the target image level in the container image is determined based on the information of the target object, and the target object is directly searched and copied at that level, avoiding searching layer by layer.
It improves the efficiency of container read and write operations, reduces lookup time, and increases the speed of operations.
Smart Images

Figure CN114398317B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of information processing, and more particularly to a container read-write method and device, an electronic device and a storage medium. BACKGROUND
[0002] Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable container that can be published on any popular Linux or Windows machine. Docker also supports virtualization. Containers are completely sandboxed and do not interface with each other.
[0003] When a file needs to be read or an existing file needs to be modified in a container, Docker will search for the file in each image layer of the container. Once the file is found, it will be copied to the container layer of the container instance, and then the file copied to the container layer will be read and modified. A container image usually includes multiple image layers. Different images include image layers with the same or different levels. In theory, there can be up to hundreds of layers. Currently, when searching for a file in an image, each image layer is sequentially checked from top to bottom to see if the file to be read or modified exists in the image layer. The subsequent image layers are not searched.
[0004] The current method of reading and writing to a container is inefficient. SUMMARY
[0005] The purpose of the present application is to provide a container read-write method, device, electronic device and storage medium, including the following technical solutions:
[0006] A container read-write method, the method comprising:
[0007] Obtaining an operation request for reading and writing a target object, the target object being arranged in a container image, the operation request carrying target object information of the target object;
[0008] Determining a target image level in which the target object is located in the container image according to the target object information and pre-established index information;
[0009] Searching for the target object in the target image level;
[0010] Copying the found target object to a container layer to perform read-write operations on the target object.
[0011] The method, preferably, the target object is a file, and the index information includes a correspondence between a file name of the target object and a target image level; and determining the target image level of the target object in the container image according to the target object information and the pre-established index information includes:
[0012] determining the target image level of the target object in the container image according to the file name of the target object from the index information;
[0013] or,
[0014] The target object is a directory, and the index information includes a correspondence between directory information of the target object and an image level; and determining the image level of the target object in the container image according to the target object information and the pre-established index information includes:
[0015] determining the target image level of the target object in the container image according to the directory information of the target object from the index information.
[0016] The method, preferably, the method of searching for the target object in the target image level includes:
[0017] jumping to a target file directory corresponding to the target image level;
[0018] searching for the target object in the target file directory.
[0019] The method, preferably, the method of copying the searched target object to a container layer includes:
[0020] determining a target container instance in which an application that issues the operation request is located;
[0021] copying the target object to the target container instance.
[0022] The method, preferably, the index information is obtained by analyzing metadata of the container image.
[0023] The method, preferably, the metadata includes a verification identifier corresponding to each level of the container image.
[0024] The method, preferably, the method of analyzing the metadata of the container image includes:
[0025] calculating a chain identifier of each image level of the container image according to the verification identifier;
[0026] obtaining a directory identifier of each image level from a file directory corresponding to the chain identifier;
[0027] determining objects contained in each mirror level according to the catalog identification;
[0028] constructing the index information according to the determined objects.
[0029] A container read-write apparatus, the apparatus comprising:
[0030] an obtaining module, configured to obtain an operation request for reading and writing a target object, the target object being arranged in a container mirror image, the operation request carrying target object information of the target object;
[0031] a determining module, configured to determine a target mirror level in which the target object is located in the container mirror image according to the target object information and pre-established index information;
[0032] a searching module, configured to search for the target object in the target mirror level;
[0033] a copying module, configured to copy the searched target object to a container layer to perform a read-write operation on the target object.
[0034] An electronic device, comprising:
[0035] a memory, configured to store a program;
[0036] a processor, configured to invoke and execute the program in the memory, and realize each step of the container read-write method according to any one of the above by executing the program.
[0037] A readable storage medium, having a computer program stored thereon, the computer program being executed by a processor to realize each step of the container read-write method according to any one of the above.
[0038] According to the above scheme, the container read-write method, apparatus, electronic device and storage medium provided by the present application are provided, an operation request for reading and writing a target object is obtained, the target object is arranged in a container mirror image, and the operation request carries target object information of the target object; a target mirror level in which the target object is located in the container mirror image is determined according to the target object information and pre-established index information; the target object is searched in the target mirror level; and the searched target object is copied to a container layer to perform a read-write operation on the target object. Based on the scheme of the present application, when a target object in a container mirror image needs to be read and written, it is not necessary to search layer by layer in the container mirror image, but only the target mirror level in which the target object is located in the container mirror image is determined according to the target object information of the target object and the pre-established index information, and the target object is directly searched in the target mirror level, so that the searching efficiency of the target object is improved, and the efficiency of reading and writing the container is also improved. BRIEF DESCRIPTION OF DRAWINGS
[0039] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 A flowchart illustrating an implementation of the container read / write method provided in this application embodiment;
[0041] Figure 2 This application provides a flowchart of an implementation for finding a target object in a target image layer.
[0042] Figure 3 A flowchart illustrating an implementation of copying the found target object to the container layer, provided in an embodiment of this application;
[0043] Figure 4 A flowchart illustrating an implementation of parsing metadata of a container image, as provided in an embodiment of this application;
[0044] Figure 5 A schematic diagram of a container read / write device provided in an embodiment of this application;
[0045] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0046] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar parts and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that illustrated herein. Detailed Implementation
[0047] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0048] like Figure 1 The diagram shown is a flowchart of one implementation of the container read / write method provided in this application, which may include:
[0049] Step S101: Obtain an operation request for reading and writing a target object, the target object being set in a container image, the operation request carrying target object information of the target object.
[0050] The target object can be a file, such as a document, audio, video, picture, etc. In addition to the file, the target object can also be other objects, such as a directory, etc.
[0051] The operation request for reading and writing the target object is issued by an application. The application can generate the operation request for reading and writing the target object in response to an operation of an operation body (a user's finger, a stylus, etc.), or the application can automatically generate the operation request for reading and writing the target object based on processing logic during running.
[0052] The target object information can be information for identifying the target object.
[0053] Step S102: Determine a target image level at which the target object is located in the container image according to the target object information and pre-established index information.
[0054] In the present application, index information corresponding to the target object is pre-established, and based on the index information and the target object information, the image level (denoted as the target image level) at which the target object is located in the container image can be determined.
[0055] Step S103: Search for the target object in the target image level.
[0056] After determining the target image level at which the target object is located in the container image, the target object is directly searched in the target image level, and other image levels (i.e., non-target image levels) do not need to be searched.
[0057] For example, assuming that the container image has a total of 127 layers, and the target image level is the 126th layer, the present application only needs to search for the target object in the 126th layer of the container image, and does not need to search in the 1st layer to the 125th layer, i.e., in the 125 image layers.
[0058] Step S104: Copy the searched target object to a container layer to perform a reading and writing operation on the target object.
[0059] The container reading and writing method provided by the embodiments of the present application comprises the following steps: obtaining an operation request for reading and writing a target object, wherein the target object is arranged in a container image, and the target object information of the target object is carried in the operation request; determining the target image level where the target object is located in the container image according to the target object information and pre-established index information; searching for the target object in the target image level; copying the searched target object to a container layer, and performing reading and writing operation on the target object. Based on the scheme of the present application, when reading and writing the target object in the container image is needed, the target object does not need to be searched layer by layer in the container image, but only needs to be searched in the target image level where the target object is located in the container image according to the target object information of the target object and the pre-established index information, so that the searching efficiency of the target object is improved, and the reading and writing efficiency of the container is also improved.
[0060] In an optional embodiment, in the case that the target object is a file, the index information can comprise the corresponding relationship between the file name of the target object and the image level; based on this, one implementation manner of the above-mentioned determining the target image level where the target object is located in the container image according to the target object information and the pre-established index information can be as follows:
[0061] determining the target image level where the target object is located in the container image according to the file name of the target object from the index information.
[0062] That is to say, in the case that the target object is a file, the target object information is the file name of the target object, wherein the file name can be defined by the user or can be defined by the system, and the specific implementation manner is not limited. Correspondingly, the image level corresponding to the file name of the target object in the index information is determined as the image level where the target object is located in the container image, that is, the target image level.
[0063] In an optional embodiment, in the case that the target object is a directory, the index information can comprise the corresponding relationship between the directory information of the target object and the image level; based on this, one implementation manner of the above-mentioned determining the target image level where the target object is located in the container image according to the target object information and the pre-established index information can be as follows:
[0064] determining the target image level where the target object is located in the container image according to the directory information of the target object from the index information.
[0065] That is, in the case where the target object is a directory, the target object information is directory information, and as an example, the directory information can be an identifier of the directory, which can be user-defined or system-defined, and the specific implementation manner is not limited. Correspondingly, the mirror level corresponding to the directory information of the target object in the index information is determined as the mirror level in which the target object is located in the container mirror, that is, the target mirror level.
[0066] In an optional embodiment, an implementation flowchart of the above-mentioned process of searching for the target object in the target mirror level can include the following steps. Figure 2
[0067] Step S201: Jumping the current directory to the file directory corresponding to the target mirror level (denoted as the target file directory).
[0068] The current directory is the directory in which the application is located when the operation request for reading and writing the target object is obtained.
[0069] The current directory can be in the target mirror level or can not be in the target mirror level.
[0070] In the case where the current directory is in the target mirror level, it can be directly jumped from the current directory to the other directory corresponding to the target mirror level.
[0071] In the case where the current directory is not in the target mirror level, it can be jumped from the mirror level in which the current directory is located to the target mirror level, and then the current directory is jumped to the target file directory corresponding to the target mirror level.
[0072] Step S202: Searching for the target object in the target file directory.
[0073] The target mirror level corresponds to at least one target file directory, and the number of target file directories corresponding to the target mirror level is determined by the actual application.
[0074] In each target file directory, it can only contain files, only contain directories (i.e. subdirectories of the target file directory), or contain both files and directories.
[0075] In each target file directory, if it contains files, it can contain at least one file; if it contains directories, it can contain at least one directory.
[0076] In an optional embodiment, an implementation flowchart of the above-mentioned process of copying the found target object to the container layer can include the following steps. Figure 3
[0077] Step S301: Determining the target container instance in which the application issuing the operation request is located.
[0078] As an example, the operation request can carry an identification of a target container instance where the application is located, so as to determine the target container instance according to the identification of the target container instance.
[0079] Step S302: Copy the target object into the target container instance.
[0080] The specific copying process can refer to the existing scheme, which will not be described in detail here.
[0081] In an optional embodiment, the above index information can be obtained by parsing the metadata of the container image.
[0082] The metadata of the container image includes a verification identifier (denoted as diffID) corresponding to each level of the container image. The verification identifier is obtained by verifying each level of the container image, such as a digest value obtained by digest calculation on all files of each level of the container image. Since the metadata of the container image including the above verification identifier is obtained, further calculation and file query are performed using the verification identifier, so as to determine which objects are contained in each level of the container image, thereby constructing the correspondence between the objects and the levels of the container image.
[0083] Optionally, an implementation flowchart for parsing the metadata of the container image provided by the embodiments of the present application can include, as shown in Figure 4
[0084] Step S401: Calculate the chain identifier (denoted as chainID) of each image level of the container image according to the verification identifier.
[0085] As an example, for each image level in the container image, the chain identifier of the image level is calculated according to the verification identifier of the image level and the chain identifier of the parent layer of the image level. The chain identifier of the bottommost image level is the verification identifier of the bottommost image level.
[0086] As an example, for the nth image level, the chainID (denoted as chainID_n) of the nth image level can be calculated by the following formula:
[0087] chainID_n = sha256 (chainID_n-1diffID_n) (1)
[0088] wherein chainID_n-1 represents the chain identifier of the parent layer of the n-th mirror level (i.e., the (n-1)-th mirror level), and diffID_n represents the check identifier of the n-th level. The chainID_n-1 and the diffID_n are connected by a space. It can be seen that in this example, the chain identifier chainID_n of the n-th mirror level is the SHA256 hash value of "chainID_n-1diffID_n".
[0089] Step S402: Obtain the directory identifier (denoted as cacheID) of each mirror level from the file directory corresponding to the chain identifier. It should be noted that the file directory corresponding to the chain identifier refers to the file directory with the chain identifier as the directory name. The chain identifier of each container mirror level corresponds to a file directory with the chain identifier as the directory name, and the file directory corresponding to the chain identifier of each container mirror level stores the directory identifier corresponding to the level. The above directory identifier is an identifier generated for each container mirror level to index the files of the container mirror level. According to the directory identifier, it can be determined which files and / or directories are included in each mirror level.
[0090] As an example, the directory identifier of each mirror level can be obtained from the file directory corresponding to the chain identifier through a specified operation command (denoted as a first operation command).
[0091] Step S403: Determine the objects contained in each mirror level according to the directory identifier.
[0092] The objects contained in each mirror level include at least one of a directory and a file.
[0093] As an example, for each mirror level, the objects contained in the mirror level can be viewed through a specified operation command (denoted as a second operation command).
[0094] Step S404: Construct the index information according to the determined objects.
[0095] Corresponding to each mirror level, after determining the objects contained in the mirror level, if the object is a file, the index information established for the object is: the correspondence between the file name of the file and the mirror level; if the object is a directory, the index information established for the object is: the correspondence between the directory information of the directory and the mirror level.
[0096] In an optional embodiment, the index information can be established only for part of the objects. Based on this, after determining the objects contained in the mirror level, for any one object, if the object belongs to a specific object, the index information can be established for the object, and if the object does not belong to the specific object, the index information is not established for the object.
[0097] As an example, a specific object can refer to an object related to an application, such as a directory or a file in the application, etc. The system files or directories of the system of the electronic device do not belong to the specific object.
[0098] In an optional embodiment, after determining the objects contained in the mirror level, for any object, it is determined whether the index information established for the object already exists. If the index information already exists (i.e., the object information of the object and the corresponding relationship with other mirror levels have been established), the index information is not established for the object. If the index information does not exist, the index information is established for the object.
[0099] As an example, for any object Ci in the i-th mirror level and any object Cj in the j-th mirror level, if the object information of Ci and Cj is the same and the paths are the same, the objects Ci and Cj are considered to be the repeatedly appearing objects in the mirror level. For any object, if the index information has been established for the object before, it means that the object has appeared before, and the index information is not established for the object this time.
[0100] As an example, the process of parsing the metadata of the container image is illustrated below. In this example, the metadata is the data in the directory Layers and the directory LowerDir:
[0101] "Layers": [
[0103] "sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a",
[0104] "sha256:dfdfadcfdf2f0c85d6f76181852095beea5f5753971efffc13ab5614f849e600",
[0105] "sha256:461c3cf87f5a35aa7434b558fc70ebcf4ff5797e346a77692a76e432552b80ee",
[0106] "sha256:3d84b9b57414889eb5072093b79eb41f87de69f69b63c4225556c4d8f325f81b",
[0107] "sha256:5b9dd696e0a4341e38b302629e71eb3434ef1eebe4effb49dc9653e09a7b75d4",
[0108] "sha256:9432d8db4603d0c759cddf55a15a55bae56046c5691abf1469d17ee8dca77ddf",
[0109] "sha256:ecee66d11b4c28e119f7c07942f78bc12082241eb6616f4dfa262280ce69d542",
[0110] "sha256:b334dbcadcb618cce1f9c08c70070bc624fa2c72933b6470763e37c716da25c2" ]
[0112] "LowerDir":
[0113] " / var / lib / docker / overlay2 / 9b70efb96eea9b03bdb5a5a3716a4734ac81be098d9288843d631e33c9c138ee / diff: / var / lib / docker / overlay2 / a316fbb7d2df2d8df1a7b070a7d05bc9c7cd70869c4b5a0f83763cc10d68838b / diff: / var / lib / docker / overlay2 / a06d5d268c094e758864bc1df0a4fc05458a63469b43f468e009a54bac7d4c62 / diff: / var / lib / docker / overlay2 / 15c1e84470058d50bd1723936bb080c985eda3cac64633894b799f8518376ffb / diff: / var / lib / docker / overlay2 / 12e8c4379e5b9688cbb574c53d56a4895be6f5f6e250c69d23ec8a67bc5bec02 / diff: / var / lib / docker / overlay2 / 89bf4b93b3255d8e642c1adeb15bd00df8cff0f70482b680578a83f2a406f842 / diff: / var / lib / docker / overlay2 / 8475f1742d4d9e5c420747c0a5e7045689c04ce3fa01f04c234fc270931ae6fb / diff"
[0114] Wherein, based on the information in Layers, the verification identifier diffID of the bottom layer (i.e. the first image layer) is:
[0115] 89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a
[0116] At the same time, the verification identifier diffID of the bottom layer is also the chain identifier chainID of the bottom layer.
[0117] Through the following cat cache-id command:
[0118] cat.. / 822ce669c04f160155fa1c2d40d96327a15f9f23ead54f16c55b63aef8bed3a4 / cache-id
[0119] The directory identification cacheID of the first image level can be obtained as follows:
[0120] 8475f1742d4d9e5c420747c0a5e7045689c04ce3fa01f04c234fc270931ae6fb
[0121] Based on the cacheID and the corresponding directory information recorded in the LowerDir, the content contained in the first image level can be determined by the following ll command:
[0122] ll
[0123] / var / lib / docker / overlay2 / 8475f1742d4d9e5c420747c0a5e7045689c04ce3fa01f04c234fc270931ae6fb / diff
[0124] The content contained in the first image level can be determined as follows:
[0125] total 16
[0126] -rw-r--r--.1 root root 12053 Dec 4 2018 anaconda-post.log
[0127] lrwxrwxrwx.1 root root 7 Dec 4 2018 bin->usr / bin
[0128] drwxr-xr-x.2 root root 6 Dec 4 2018 dev
[0129] drwxr-xr-x.47 root root 4096 Dec 4 2018 etc
[0130] drwxr-xr-x.2 root root 6 Apr 11 2018 home
[0131] In the above lines, the content after “2018” is the object information of the object contained in the image level, and a corresponding relationship between the object information in the above lines and the first image level can be established.
[0132] For the second image level, the verification identification diffID is:
[0133] dfdfadcfdf 2f0c85d6f76181852095beea5f5753971efffc13ab5614f849e600
[0134] The chainID of the parent layer (i.e., the first mirror level) of the second mirror level is:
[0135] 89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a Then, based on the foregoing formula (1), the chainID of the second mirror level can be obtained as:
[0136] 822ce669c04f160155fa1c2d40d96327a15f9f23ead54f16c55b63aef8bed3a4
[0137] The directory identifier cacheID of the second mirror level can be obtained by the cat cache-id command as:
[0138] 89bf4b93b3255d8e642c1adeb15bd00df8cff0f70482b680578a83f2a406f842
[0139] The content contained in the second mirror level can be determined by the ll command as:
[0140] total 0
[0141] drwxr-xr-x.2 root root 42 Apr 26 2021 opt
[0142] In this example, the content opt after "2021" is the object information of the object contained in the mirror level, and the corresponding relationship between the object information opt and the second mirror level can be established.
[0143] As shown in Table 1, the index information corresponding to the first mirror level and the second mirror level provided by the embodiment of the present application is shown.
[0144] Table 1
[0145] Mirror level Files and / or directories 2 opt 1 anaconda-post.log bin dev etc home
[0146] Similarly, the corresponding relationship between the object information of the object contained in each mirror level and the mirror level is established.
[0147] Corresponding to the method embodiment, the embodiment of the present application also provides a container reading and writing device, asFigure 5 As shown in FIG. 1, a structure diagram of a container read-write device provided by an embodiment of the present application can include:
[0148] The container read-write device provided by the embodiment of the present application includes an acquisition module 501, a determination module 502, a search module 503 and a copy module 504.
[0149] The acquisition module 501 is configured to acquire an operation request for reading and writing a target object, wherein the target object is arranged in a container image, and the operation request carries target object information of the target object.
[0150] The determination module 502 is configured to determine a target image level in which the target object is located in the container image according to the target object information and pre-established index information.
[0151] The search module 503 is configured to search for the target object in the target image level.
[0152] The copy module 504 is configured to copy the searched target object to a container layer to perform a read-write operation on the target object.
[0153] The container read-write device provided by the embodiment of the present application can directly search for a target object in a target image level when reading and writing a target object in a container image, without searching for the target object layer by layer in the container image, thereby improving the search efficiency of the target object and the efficiency of reading and writing the container.
[0154] In an optional embodiment, the target object is a file, and the index information includes a corresponding relationship between a file name of the target object and an image level; the determination module 502 is configured to:
[0155] determine the target image level in which the target object is located in the container image from the index information according to the file name of the target object.
[0156] Or,
[0157] the target object is a directory, and the index information includes a corresponding relationship between directory information of the target object and an image level; the determination module 502 is configured to:
[0158] determine the target image level in which the target object is located in the container image from the index information according to the directory information of the target object.
[0159] In an optional embodiment, the search module 503 is configured to:
[0160] jump the current directory to a target file directory corresponding to the target image level;
[0161] find the target object in the target file directory.
[0162] In an optional embodiment, the copying module 504 is configured to:
[0163] determine a target container instance in which an application that issues the operation request is located;
[0164] copy the target object into the target container instance.
[0165] In an optional embodiment, the apparatus further includes:
[0166] a parsing module configured to parse metadata of the container image to obtain the index information.
[0167] In an optional embodiment, the metadata includes a verification identifier corresponding to each level of the container image.
[0168] In an optional embodiment, the parsing module is configured to:
[0169] calculate a chain identifier of each image level of the container image according to the verification identifier;
[0170] obtain a directory identifier of each image level from a file directory corresponding to the chain identifier;
[0171] determine objects contained in each image level according to the directory identifier;
[0172] construct the index information according to the determined objects.
[0173] Corresponding to the method embodiments, the present application also provides an electronic device, a structural schematic diagram of which is shown in Figure 6 The electronic device can include at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4.
[0174] In the embodiments of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 complete communication with each other through the communication bus 4.
[0175] The processor 1 can be a central processing unit CPU, or a specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application, etc.
[0176] The memory 3 can comprise a high-speed RAM memory and can also comprise a non-volatile memory, such as at least one disk memory.
[0177] The memory 3 stores a program, and the processor 1 can invoke the program stored in the memory 3, and the program is used for:
[0178] An operation request for reading and writing a target object is acquired, the target object is arranged in a container image, and the target object information of the target object is carried in the operation request;
[0179] The target image level in which the target object is located in the container image is determined according to the target object information and pre-established index information.
[0180] The target object is searched in the target image level.
[0181] The target object searched is copied to a container layer to perform reading and writing operations on the target object.
[0182] Optionally, the refinement function and the extension function of the program can refer to the description above.
[0183] The embodiments of the present application also provide a storage medium which can store a program suitable for a processor to execute, and the program is used for:
[0184] An operation request for reading and writing a target object is acquired, the target object is arranged in a container image, and the target object information of the target object is carried in the operation request;
[0185] The target image level in which the target object is located in the container image is determined according to the target object information and pre-established index information.
[0186] The target object is searched in the target image level.
[0187] The target object searched is copied to a container layer to perform reading and writing operations on the target object.
[0188] Optionally, the refinement function and the extension function of the program can refer to the description above.
[0189] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0190] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.
[0191] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0192] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present alone, or two or more units can be integrated in one unit.
[0193] It should be understood that the features in the embodiments of the present application, each embodiment, feature can be combined with each other, and can achieve the purpose of solving the above technical problems.
[0194] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the technical solutions that essentially contribute to the prior art can be embodied in the form of software products, which are stored in a storage medium and include a number of instructions for making a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk and various program code storage media.
[0195] The foregoing description of the disclosed embodiments enables a person skilled in the art to make or use the application. Modifications of these embodiments will occur to persons of skill in the art, and that the generic principles defined herein can be applied to other embodiments without departing from the spirit or scope of the application. Therefore, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A container read-write method, the method comprising: obtaining an operation request for reading and writing a target object, the target object being arranged in a container image, the operation request carrying target object information of the target object; determining a target image level in which the target object is located in the container image according to the target object information and pre-established index information, the target image level corresponding to at least one target file directory; the target object being a file, the index information including a corresponding relationship between a file name of the target object and an image level; or the target object being a directory, the index information including a corresponding relationship between directory information of the target object and an image level; the index information being obtained by analyzing metadata of the container image, the metadata including a verification identifier corresponding to each level of the container image, the analyzing of the metadata of the container image including: for each image level in the container image, calculating a chain identifier of the image level according to the verification identifier of the image level and a chain identifier of a parent layer of the image level; obtaining a directory identifier of each image level from a file directory corresponding to the chain identifier; determining objects contained in each image level according to the directory identifier; and constructing the index information according to the determined objects; jumping a current directory to a target file directory corresponding to the target image level, and searching for the target object in the target file directory; wherein, in a case where the current directory is at the target image level, jumping directly from the current directory to another directory corresponding to the target image level; in a case where the current directory is not at the target image level, jumping from an image level in which the current directory is located to the target image level, and jumping the current directory to the target file directory corresponding to the target image level; copying the searched target object to a container layer to perform a read-write operation on the target object.
2. The method of claim 1, wherein the target object is a file, and the index information comprises a correspondence between a file name of the target object and the mirror level. The determining of the target image level in which the target object is located in the container image according to the target object information and the pre-established index information comprises: determining the target image level in which the target object is located in the container image from the index information according to a file name of the target object; or, the target object being a directory, the index information including a corresponding relationship between directory information of the target object and an image level; the determining of the image level in which the target object is located in the container image according to the target object information and the pre-established index information comprises: determining the target image level in which the target object is located in the container image from the index information according to the directory information of the target object. 3.The method of claim 1, the copying of the searched target object to a container layer comprising: determining a target container instance in which an application issuing the operation request is located; copying the target object into the target container instance. 4.A container read-write apparatus, the apparatus comprising: An obtaining module is configured to obtain an operation request for reading and writing a target object, the target object being arranged in a container image, and the operation request carrying target object information of the target object; A determining module is configured to determine a target image level of the target object in the container image according to the target object information and pre-established index information, the target image level corresponding to at least one target file directory; the target object is a file, and the index information includes a corresponding relationship between a file name of the target object and an image level; or the target object is a directory, and the index information includes a corresponding relationship between directory information of the target object and an image level; the index information is obtained by analyzing metadata of the container image, and the metadata includes a verification identifier corresponding to each level of the container image; the metadata of the container image is analyzed, including: for each image level in the container image, calculating a chain identifier of the image level according to a verification identifier of the image level and a chain identifier of a parent layer of the image level; obtaining a directory identifier of each image level from a file directory corresponding to the chain identifier; determining objects contained in each image level according to the directory identifier; and constructing the index information according to the determined objects; A searching module is configured to jump a current directory to a target file directory corresponding to the target image level, and search for the target object in the target file directory; in a case where the current directory is at the target image level, directly jumping from the current directory to another directory corresponding to the target image level; in a case where the current directory is not at the target image level, jumping from an image level where the current directory is located to the target image level, and jumping the current directory to the target file directory corresponding to the target image level; A copying module is configured to copy the found target object to a container layer to perform reading and writing operations on the target object. 5.An electronic device, comprising: a memory configured to store a program; a processor configured to invoke and execute the program in the memory, and implement each step of the container reading and writing method according to any one of claims 1-3 by executing the program. 6.A readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement each step of the container reading and writing method according to any one of claims 1-3.
Citation Information
Patent Citations
Mirror image packet processing method and device and electronic equipment
CN112084006A
Docker container mirror image storage method and device, docker container mirror image pulling method and device and computer readable storage medium
CN112433810A
File query method and device, computer equipment and storage medium
CN113127519A