Container-based read-write control method, device and equipment
By separating the mirror read-only layer of the container root file system from the read-write layer, and using the host local directory to achieve data persistence, the problem of data loss after container restart is solved, ensuring the normal operation of the container application.
Patent Information
- Application Number
- CN202411252984.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-13
AI Technical Summary
When the container is restarted, the root file system is rebuilt, resulting in data loss in the container's read and write layer, affecting the normal operation of the application.
By separating the mirror read-only layer of the container root file system from the container read-only layer, the mirror read-only layer is provided by the original container root file system after the container image is decompressed. The container read-only layer is implemented by the local directory on the host machine, using overlay The technology performs joint mounts to generate the root file system of the container.
It realizes persistence of the data of the container read and write layer, ensuring that data is not lost after the container is restarted, and supports the data persistence capability of the container read and write layer.
Smart Images

Figure CN119127400A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a container-based read-write control method, device and equipment. Background Art
[0002] Container technology, also known as container virtualization, is a lightweight virtualization technology. When a container runs in a host machine, it needs to use a root file system (rootfs). Currently, the root file system of a container is created based on a container image. The root file system of a container consists of two parts: the image read-only layer (read-only layer) and the container read-write layer (read-write layer).
[0003] Currently, since containers are usually designed to be stateless, when a container is restarted, the root file system will be recreated based on the container image, and the data written by the container in the container read-write layer will be lost. However, if the data in the read-write layer of the root file system container is lost, it may affect the normal operation of the application using the container. Therefore, how to ensure that the data written to the container root file system is not lost after the container is restarted is a technical problem that needs to be solved. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a container-based read-write control method, device and equipment to solve the technical problem of data loss in the container root file system after the container is restarted.
[0005] To solve the above problems, the technical solutions provided in the embodiments of the present application are as follows:
[0006] In a first aspect, an embodiment of the present application provides a container-based read-write control method, the method comprising:
[0007] In response to starting the container, creating an original container root file system according to the container image, wherein the original container root file system includes an original image read-only layer and an original container read-write layer;
[0008] Create a local directory on the host machine;
[0009] The original container root file system is used as the mirror read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate a container root file system.
[0010] In a second aspect, an embodiment of the present application provides a container-based read-write control device, the device comprising:
[0011] A first creation unit is used to create an original container root file system according to the container image in response to the startup of the container, where the original container root file system includes an original image read-only layer and an original container read-write layer;
[0012] The second creation unit is used to create a local directory on the host machine;
[0013] The generating unit is used to use the original container root file system as the mirror read-only layer of the container root file system and the local directory as the container read-write layer of the container root file system to generate the container root file system.
[0014] In a third aspect, an embodiment of the present application provides a container-based read-write control device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the container-based read-write control method as described above is implemented.
[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes the container-based read-write control method as described above.
[0016] It can be seen that the embodiments of the present application have the following beneficial effects:
[0017] In the embodiment of the present application, when the container is started, the original container root file system is created according to the container image, and a local directory is created in the host machine. The original container root file system is used as the image read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate the container root file system. Therefore, when the container is running, after writing data to the container read-write layer of the container root file system, the data is written to the local directory of the host machine, and the container read-write layer of the container root file system has data persistence capabilities. After the container is restarted, the local directory in the host machine is not affected, and the data in the container read-write layer of the container root file system will not be lost. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A schematic diagram of an exemplary application scenario provided for an embodiment of the present application;
[0019] Figure 2 A flowchart of a container-based read-write control method provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram of establishing a container root file system in an embodiment of the present application;
[0021] Figure 4 A schematic diagram of establishing an original container root file system in an embodiment of the present application;
[0022] Figure 5 A schematic diagram of a container-based read-write control device provided in an embodiment of the present application;
[0023] Figure 6 A schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0025] In order to facilitate understanding and explanation of the technical solution provided by the embodiments of the present application, the background technology of the embodiments of the present application will be described below.
[0026] The root file system required by the container runtime is created by the container image. The root file system of the container consists of two parts: the image read-only layer and the container read-write layer. At present, since containers are usually designed to be stateless, when the container is restarted, the root file system will be recreated based on the container image, and the data written by the container in the container read-write layer will be lost. However, if the data in the container read-write layer is lost, it may affect the normal operation of the application using the container. For example, for some rich container applications, this type of application is containerized from traditional applications, but it is not completely containerized, and containers are often used in the same way as virtual machines. Some temporary files will be read and written under the container read-write layer of the root file system, and multiple processes will be managed based on the written data. Therefore, if the data in the root file system is lost after the container is restarted, it will affect the normal operation of such applications.
[0027] Based on this, the embodiments of the present application provide a container-based read-write control method, device and equipment, which separates the container read-write layer of the container root file system from the image read-only layer. The image read-only layer is provided by the original container root file system after the container image is decompressed, and the container read-write layer is implemented through a separate local directory on the host machine. The container read-write layer and the image read-only layer are jointly mounted through overlay to generate the container's root file system. The container read-write layer is implemented through a local directory on the host machine, and the data written to the container read-write layer will not be lost, supporting the data persistence capability of the container read-write layer.
[0028] In order to facilitate understanding of the container-based read-write control method provided in the embodiment of the present application, Figure 1 See the example scenario shown in the figure. Figure 1 As shown, this figure is a schematic diagram of an exemplary application scenario provided in an embodiment of the present application.
[0029] The embodiments of the present application can be applied to a host machine for creating a container. In the host machine, when the container is started, the snapshotter component in containerd (a lightweight container management tool) generates the original container root file system according to the container image. The original container root file system includes the original image read-only layer and the original container read-write layer. The original image read-only layer may include multiple layers, such as layer1, layer2, and layer3, and the original container read-write layer is usually a single layer, such as a read-write layer. Generate a local directory on the host machine. Use the original container root file system as the image read-only layer of the container root file system, and use the local directory on the host machine as the container read-write layer of the container root file system to generate the container's root file system. The container writes data to the container read-write layer at runtime, and the data is written to the local directory of the host machine. After the container is restarted, the local directory in the host machine is not affected, and the data in the container read-write layer of the container root file system will not be lost.
[0030] Those skilled in the art will understand that Figure 1 The framework diagram shown is only an example in which the embodiments of the present application can be implemented. The scope of application of the embodiments of the present application is not limited by any aspect of the framework.
[0031] To facilitate understanding of the embodiments of the present application, a container-based read-write control method provided in the embodiments of the present application is described below with reference to the accompanying drawings.
[0032] See also Figure 2 As shown in FIG. 1 , this figure is a flow chart of a container-based read-write control method provided in an embodiment of the present application, such as Figure 2 As shown, the method may include S201-S203:
[0033] S201: In response to starting the container, create an original container root file system according to the container image, where the original container root file system includes an original image read-only layer and an original container read-write layer.
[0034] When the container is started, the root file system of the container needs to be created. First, the container image can be downloaded from the image repository. The container image is decompressed layer by layer to obtain the original container root file system. The original container root file system is a container root file system established in a traditional way. The original container root file system may include an original image read-only layer and an original container read-write layer, wherein the original image read-only layer may include one or more layers, and the original container read-write layer is usually one layer. The specific implementation process of S201 creating the original container root file system according to the container image can be referred to the subsequent embodiments, which will not be repeated here.
[0035] S202: Create a local directory on the host machine.
[0036] When the root file system of a container needs to be created, a local directory is created on the host machine, and the local directory corresponds to the container to be created.
[0037] In a possible implementation, the specific implementation of S202 creating a local directory on the host machine may include:
[0038] Create a local directory corresponding to the container on the host.
[0039] In actual applications, the name of the local directory created on the host machine may include the name of the container created on the host machine, so that the local directory corresponds to the container created on the host machine. For example, create a directory named / run / container / on the host machine.<pod name> -<container name> The local directory of the container. Where container name is the container name, pod name is the Pod name. A Pod can encapsulate one or more containers, which share the network and storage resources of the Pod. The local directory can correspond to the container created on the host.
[0040] It is understandable that the embodiment of the present application does not limit the execution order between S201 and S202. S201 may be executed first and then S202, or S202 may be executed first and then S201, or S201 and S202 may be executed in parallel.
[0041] S203: Using the original container root file system as the mirror read-only layer of the container root file system and using the local directory as the container read-write layer of the container root file system to generate the container root file system.
[0042] After the original container root file system and the local directory on the host are generated, the original container root file system is used as the mirror read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate the container root file system. This is equivalent to adding another layer of local directory as the container read-write layer on top of the original container root file system to ensure that the data in the container read-write layer is not lost. The specific implementation process of generating the container root file system in S203 can be found in the subsequent embodiments, which will not be repeated here.
[0043] In this way, the embodiment of the present application creates an original container root file system based on the container image when the container is started, and creates a local directory in the host machine. The original container root file system is used as the image read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate the container root file system. Therefore, when the container is running, after writing data to the container read-write layer of the container root file system, the data is written to the local directory of the host machine, and the container read-write layer of the container root file system has data persistence capabilities. After the container is restarted, the local directory in the host machine is not affected, and the data in the container read-write layer of the container root file system will not be lost.
[0044] After the container root file system is created, processes in the container can read data from the root file system and write data to the root file system.
[0045] In a possible implementation, the container-based read / write control method provided in the embodiment of the present application may further include:
[0046] When a process in the container requests to write data, the written data is saved in the local directory.
[0047] When the process in the container needs to write data to the established root file system, the data is written to the container read-write layer of the root file system. Since the container read-write layer of the root file system is implemented by the local directory in the host machine, the written data is saved in the local directory of the host machine. The written data has persistence and will not be lost with the restart of the container.
[0048] In a possible implementation, the container-based read / write control method provided in the embodiment of the present application may further include:
[0049] When the process in the container requests to read data, the requested data is read from the local directory;
[0050] If the requested data does not exist in the local directory, the requested data is read from the image read-only layer of the container root file system.
[0051] When a process in a container needs to read data from the established root file system, it first reads data from the container read-write layer of the root file system, that is, reads data from the local directory. If the container read-write layer, that is, the local directory, does not contain the requested data, it further reads data from the image read-only layer of the container root file system.
[0052] The container root file system established by the embodiment of the present application can read and write data normally, and the written data will not change with the change of the container state.
[0053] In a possible implementation, the container-based read / write control method provided in the embodiment of the present application may further include:
[0054] In response to the restart of the container, re-create the original container root file system according to the container image, where the original container root file system includes the original image read-only layer and the original container read-write layer;
[0055] The original container root file system is used as the image read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate the container root file system.
[0056] In the embodiment of the present application, after the container is restarted, steps S201 and S203 are re-executed, and the contents of the image read-only layer of the container root file system are replaced, while the contents of the container read-write layer of the container root file system are not lost because they are stored on the host machine. After the container is restarted, the image read-only layer and the container read-write layer are re-mounted by overlay to generate the container root file system, and the data in the container read-write layer is not lost.
[0057] In a possible implementation, S203 uses the original container root file system as the image read-only layer of the container root file system, and uses the local directory as the container read-write layer of the container root file system. The specific implementation of generating the container root file system may include:
[0058] The original container root file system is used as the lower directory, the local directory is used as the upper directory, and the lower directory and the upper directory are mounted together as a merged directory as the container root file system.
[0059] In actual applications, the original container root file system is used as the lower directory (Lower Dir), the local directory (Local Dir) in the host machine is used as the upper directory (Upper Dir), and the lower directory and the upper directory are mounted together as a merged directory (Merge Dir) to generate the container root file system (Rootfs).
[0060] See also Figure 3 As shown, a schematic diagram of establishing a container root file system in an embodiment of the present application is shown. The embodiment of the present application adopts a read-write separation method for the container root file system Rootfs. The snapshotter component of Containerd only provides an image read-only layer, and the container read-write layer is provided by the local file system of the host machine.
[0061] In actual applications, use the overlay snapshotter component in Containerd to create the original container root file system (containerd rootfs). The original container root file system includes the original image read-only layer (such as layer1, layer2, layer3) and the original container read-write layer (such as read-write layer). The original container root file system is used as the image read-only layer of the container root file system. Among them, overlay snapshotter is the snapshotter component corresponding to the Overlay layered file system. Containerd supports overlay snapshotter by default.
[0062] When preparing the container root file system, the overlay snapshotter creates a directory called / run / container / on the host.<pod name> -<container name> The local directory (Local Dir).
[0063] Use the original container root file system as Lower Dir and the local directory as Upper Dir, mount overlayfs through overlay, and get Merge Dir as the final root file system of the container.
[0064] When the process in the container reads and writes data, the written content is saved in the Local Dir directory.
[0065] When the container is restarted, the original container root file system is regenerated, and the original container root file system is mounted with the local directory through overlay to obtain the final root file system of the container.<pod name> -<container name> The local directory is persisted on the host machine, so restarting the container does not affect the content, which means that the persistence capability of the container read-write layer is achieved.
[0066] In a possible implementation, S201, in response to the startup of the container, a specific implementation of creating the original container root file system according to the container image may include:
[0067] A1: In response to the startup of the container, the container image is decompressed layer by layer to generate a read-only layer of the original image.
[0068] A2: Create the original container read-write layer based on the original image read-only layer.
[0069] A3: Combine the original image read-only layer and the original container read-write layer to form the original container root file system.
[0070] In the embodiment of the present application, when the container is started, after obtaining the container image, at least one original image read-only layer can be obtained by decompressing it layer by layer. Based on the original image read-only layer, an original container read-write layer can be further established to generate the original container root file system.
[0071] See also Figure 4 As shown, a schematic diagram of creating the original container root file system is shown. In the process of snapshotter preparing the original container root file system, the key is the Prepare and Commit methods, which are explained with a specific example.
[0072] The snapshotter prepares directories layer by layer based on the container image layer. For example, the first layer is directly decompressed to the specified directory as the first layer snapshot. When preparing the second layer image layer, the second layer image layer is decompressed on top of the file system content of the first layer snapshot as the second layer snapshot. Similarly, when preparing the nth layer snapshot, the nth layer image layer is decompressed on the basis of the n-1 layer snapshot. When preparing the snapshot, first create a readable and writable Active snapshot through Prepare, mount the snapshot, decompress the image into the snapshot, and then commit the snapshot as a committed snapshot. The container image is composed of multiple layers of read-only layers, and the container rootfs is implemented by the image read-only layer layer plus a container read-write layer. The implementation mechanism of snapshotter corresponds one-to-one to the image layer.
[0073] Specifically, in Figure 4 The container image in is a three-layer container image. When snapshotter prepares snapshots of the image, it first creates an Active state snapshot 1' through Prepare. This call returns the mount information of an empty directory (with parent as ""), which is a readable and writable folder after mounting.
[0074] Decompress the first layer image layer (layer1) into the folder, call Commit to generate snapshot1 in the committed (read-only) state, and the parent snapshot of snapshot1 is empty. Then remove snapshot 1'. At this time, after calling the mount information returned by the Mount, Prepare, and View operations on snapshot1, the file system content is the decompressed content of the image layer 1.
[0075] Create an Active state snapshot 2' with snapshot1 as the parent snapshot through Prepare. After snapshot 2' is mounted, the directory will contain the contents of the first layer of the image layer. At this time, decompress the second layer of the image layer (layer2) to the directory where snapshot 2' is mounted, and call Commit again to generate the committed state snapshot2. At this time, after the mount information returned by calling Mount, Prepare, and View operations on snapshot2 is mounted, the file system content is the decompressed contents of image layer 1 and image layer2 in sequence.
[0076] Similarly, through Prepare, snapshot2 is used as the parent snapshot to create an Active state snapshot 3', and then the third layer image layer (layer3) is decompressed into it, and finally snapshot3 in the Committed state is generated. Snapshot1, snapshot2, and snapshot3 are all read-only and immutable. At this time, after the mount information returned by calling Mount, Prepare, and View operations on snapshot3 is mounted, the file system content is the decompressed content of image layer1, image layer2, and image layer3 in sequence, as the image read-only layer.
[0077] When starting the container, call the Prepare interface of snapshotter to create an Active snapshot4 with snapshot3 as the parent snapshot. At this time, the mount information returned by the Prepare call is mounted to the original rootfs directory of the container. The content contained in the original rootfs directory of the container is the content of the image layer1, layer2, and layer3 superimposed in sequence. At the same time, because the snapshot is in the Active state, the directory is readable and writable, and serves as the container read-write layer. Thus, the original root file system of the container is created.
[0078] Based on the container-based read-write control method provided by the above method embodiment, the embodiment of the present application also provides a container-based read-write control device, which will be described below in conjunction with the accompanying drawings.
[0079] See also Figure 5 As shown in FIG. 1 , this figure is a schematic diagram of the structure of a container-based read-write control device provided in an embodiment of the present application. Figure 5 As shown, the container-based read-write control device includes:
[0080] A first creation unit 501 is used to create an original container root file system according to the container image in response to the startup of the container, where the original container root file system includes an original image read-only layer and an original container read-write layer;
[0081] The second creation unit 502 is used to create a local directory on the host machine;
[0082] The generating unit 503 is configured to use the original container root file system as the mirror read-only layer of the container root file system and the local directory as the container read-write layer of the container root file system to generate a container root file system.
[0083] In a possible implementation manner, the device further includes:
[0084] The triggering unit is used to trigger the first creation unit to re-create the original container root file system according to the container image in response to the restart of the container, where the original container root file system includes the original image read-only layer and the original container read-write layer; trigger the generation unit to use the original container root file system as the image read-only layer of the container root file system and the local directory as the container read-write layer of the container root file system to generate the container root file system.
[0085] In a possible implementation manner, the generating unit is specifically configured to:
[0086] The original container root file system is used as a lower directory, the local directory is used as an upper directory, and the lower directory and the upper directory are jointly mounted as a merged directory as the container root file system.
[0087] In a possible implementation manner, the second creating unit is specifically configured to:
[0088] Create a local directory corresponding to the container on the host.
[0089] In a possible implementation manner, the first creating unit is specifically configured to:
[0090] In response to the startup of the container, decompress the container image layer by layer to generate a read-only layer of the original image;
[0091] Establishing an original container read-write layer based on the original image read-only layer;
[0092] The original image read-only layer and the original container read-write layer form an original container root file system.
[0093] In a possible implementation manner, the device further includes:
[0094] The writing unit is used to save the written data in the local directory when the process in the container requests to write data after generating the container root file system.
[0095] In a possible implementation manner, the device further includes:
[0096] The reading unit is used to read the requested data from the local directory when the process in the container requests to read data after the container root file system is generated; if the requested data does not exist in the local directory, read the requested data from the mirror read-only layer of the container root file system.
[0097] In the embodiment of the present application, when the container is started, the original container root file system is created according to the container image, and a local directory is created in the host machine. The original container root file system is used as the image read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate the container root file system. Therefore, when the container is running, after writing data to the container read-write layer of the container root file system, the data is written to the local directory of the host machine, and the container read-write layer of the container root file system has data persistence capabilities. After the container is restarted, the local directory in the host machine is not affected, and the data in the container read-write layer of the container root file system will not be lost.
[0098] In addition, an embodiment of the present application further provides a computer program product, including computer program instructions. When the computer program instructions are executed on a computer, the computer executes any of the container-based read-write control methods described above.
[0099] Based on the container-based read-write control method provided by the above method embodiment, the present application also provides an electronic device, including: one or more processors; a storage device, on which one or more programs are stored, when the one or more programs are executed by the one or more processors, the one or more processors implement the container-based read-write control method described in any of the above embodiments.
[0100] Reference below Figure 6, which shows a schematic diagram of the structure of an electronic device 1300 suitable for implementing the embodiment of the present application. The terminal device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (portable android devices), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (televisions), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0101] like Figure 6 As shown, the electronic device 1300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage device 1306 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the electronic device 1300 are also stored. The processing device 1301, the ROM 1302, and the RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.
[0102] Typically, the following devices may be connected to the I / O interface 1305: an input device 1306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1306 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1309. The communication device 1309 may allow the electronic device 1300 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 1300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0103] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1309, or installed from the storage device 1306, or installed from the ROM 1302. When the computer program is executed by the processing device 1301, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0104] The electronic device provided in the embodiment of the present application and the container-based read-write control method provided in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0105] Based on the container-based read-write control method provided by the above method embodiment, an embodiment of the present application provides a computer-readable medium on which a computer program is stored, wherein when the program is executed by a processor, the container-based read-write control method as described in any of the above embodiments is implemented.
[0106] It should be noted that the computer-readable medium in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In an embodiment of the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0107] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0108] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0109] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the container-based read-write control method.
[0110] The computer program code for performing the operation of the embodiment of the present application can be written in one or more programming languages or a combination thereof, and the above-mentioned programming languages include but are not limited to object-oriented programming languages-such as Java, Smalltalk, C++, and also include conventional procedural programming languages-such as "C" language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network-including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0111] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0112] The units involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the unit / module does not, in some cases, constitute a limitation on the unit itself.
[0113] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0114] In the context of the present application embodiment, machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable medium can include but is not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the above. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.
[0115] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0116] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0117] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0118] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0119] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A container-based read-write control method, characterized in that: The method comprises: In response to starting the container, creating an original container root file system according to the container image, wherein the original container root file system includes an original image read-only layer and an original container read-write layer; Create a local directory on the host machine; The original container root file system is used as the mirror read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate a container root file system.
2. The method according to claim 1, characterized in that The method further comprises: In response to the restart of the container, re-create the original container root file system according to the container image, where the original container root file system includes the original image read-only layer and the original container read-write layer; The original container root file system is used as the mirror read-only layer of the container root file system, and the local directory is used as the container read-write layer of the container root file system to generate a container root file system.
3. The method according to claim 1 or 2, characterized in that: The method of using the original container root file system as a mirror read-only layer of the container root file system and using the local directory as a container read-write layer of the container root file system to generate a container root file system includes: The original container root file system is used as a lower directory, the local directory is used as an upper directory, and the lower directory and the upper directory are jointly mounted as a merged directory as the container root file system.
4. The method according to claim 1, characterized in that: The step of creating a local directory on the host machine includes: Create a local directory corresponding to the container on the host.
5. The method according to claim 1 or 2, characterized in that: In response to the startup of the container, creating the original container root file system according to the container image, including: In response to the startup of the container, decompress the container image layer by layer to generate a read-only layer of the original image; Establishing an original container read-write layer based on the original image read-only layer; The original image read-only layer and the original container read-write layer form an original container root file system.
6. The method according to claim 1 or 4, characterized in that: The method further comprises: After the container root file system is generated, when a process in the container requests to write data, the written data is saved in the local directory.
7. The method according to claim 1 or 4, characterized in that: The method further comprises: After the container root file system is generated, when a process in the container requests to read data, the requested data is read from the local directory; If the data requested to be read does not exist in the local directory, the data requested to be read is read from the mirror read-only layer of the container root file system.
8. A container-based read-write control device, characterized in that: The device comprises: A first creation unit is used to create an original container root file system according to the container image in response to the startup of the container, where the original container root file system includes an original image read-only layer and an original container read-write layer; The second creation unit is used to create a local directory on the host machine; The generating unit is used to use the original container root file system as the mirror read-only layer of the container root file system and the local directory as the container read-write layer of the container root file system to generate the container root file system.
9. A container-based read-write control device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the container-based read / write control method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the container-based read-write control method according to any one of claims 1 to 7.
