A container creation method and device

By creating and mounting a virtual disk with a preset capacity on the embedded platform, the problem of lack of container quota restrictions on the embedded platform is solved, and effective management of container disk space is achieved.

CN113190325BActive Publication Date: 2025-01-21DATANG MICROELECTRONICS TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110383555.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-09
Publication Date
2025-01-21
Estimated Expiration
2041-04-09

AI Technical Summary

Technical Problem

On embedded platforms, the lack of a common container quota restriction scheme has led to the inability to effectively manage the disk space of containers.

Method used

By creating a virtual disk with a preset capacity and mounting it to the root file system directory of the container, the container's quota restriction function is implemented. Specific steps include creating a root directory, creating a virtual disk, mounting the virtual disk, and formatting to create a file system.

Benefits of technology

It implements universal quota limits for containers, avoids excessive disk space usage, and improves container management efficiency on embedded platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113190325B_ABST
    Figure CN113190325B_ABST
Patent Text Reader

Abstract

The present application discloses a container creation method and device, the method comprising: creating a root directory of a container to be created; creating a virtual disk of a preset capacity; creating an empty root file system directory under the root directory; mounting the virtual disk to the root file system directory; and creating a root file system under the root file system directory. The container creation method and device disclosed in the present application realize a general container quota restriction function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to computer technology, and more particularly to a method and device for creating a container. Background Art

[0002] Since Docker container technology is heavy for embedded platforms, the containers in embedded environments are mainly Linux LXC, and the Linux kernel of embedded platforms is often streamlined (for example, the Alpine Linux kernel is only a few megabytes), so it does not have most of the advanced features of Linux (for example, the quota function), resulting in the lack of a universal container quota restriction solution on embedded platforms. Summary of the invention

[0003] The present application provides a container creation method, which can implement a general container quota restriction function.

[0004] The present application provides a container creation method, including:

[0005] Create the root directory of the container to be created;

[0006] Create a virtual disk with preset capacity;

[0007] Creating an empty root file system directory under the root directory;

[0008] Mounting the virtual disk to the root file system directory;

[0009] A root file system is created under the root file system directory.

[0010] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0011] Creates an empty virtual disk file of a preset size.

[0012] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0013] A virtual disk file of a preset size is created by using a sparse file technology and attribute information of the virtual disk file is set.

[0014] In an exemplary embodiment, after creating a virtual disk of preset capacity and before mounting the virtual disk to the root file system directory, the method further includes:

[0015] The virtual disk file is formatted and a first file system is established.

[0016] In an exemplary embodiment, the invention comprises:

[0017] The first file system includes a second generation extended ext2 file system, a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

[0018] The present application provides a container creation device, including a memory and a processor.

[0019] The memory is used to store a program for creating a container;

[0020] The processor is configured to read and execute the program for creating a container, and perform the following operations:

[0021] Create the root directory of the container to be created;

[0022] Create a virtual disk with preset capacity;

[0023] Creating an empty root file system directory under the root directory;

[0024] Mounting the virtual disk to the root file system directory;

[0025] A root file system is created under the root file system directory.

[0026] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0027] Creates an empty virtual disk file of a preset size.

[0028] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0029] A virtual disk file of a preset size is created by using a sparse file technology and attribute information of the virtual disk file is set.

[0030] In an exemplary embodiment, the processor is used to read and execute the program for container creation, and further performs the following operations:

[0031] The virtual disk file is formatted and a first file system is established.

[0032] In an exemplary embodiment, it is characterized in that:

[0033] The first file system includes a second generation extended ext2 file system, a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

[0034] The embodiment of the present application implements a general container quota restriction function by mounting a created virtual disk of a preset capacity to the root file system directory.

[0035] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by implementing the present application. Other advantages of the present application can be realized and obtained by the schemes described in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The accompanying drawings are used to provide an understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.

[0037] Figure 1 A schematic diagram of a container creation method according to an embodiment of the present application;

[0038] Figure 2 A schematic diagram of a method for creating a container with a disk quota in the prior art;

[0039] Figure 3 A schematic diagram of a container creation device according to an embodiment of the present application; DETAILED DESCRIPTION

[0040] Figure 1 This is a schematic diagram of a container creation method according to an embodiment of the present application. Figure 1 As shown, the container creation method of this embodiment includes steps S11-S14:

[0041] S11. Create a root directory of the container to be created.

[0042] S12. Create a virtual disk with a preset capacity.

[0043] S13, creating an empty root file system directory under the root directory;

[0044] S14, mounting the virtual disk to the root file system directory;

[0045] S15. Create a root file system in the root file system directory.

[0046] The container creation process will create a directory with the same name as the specified container name parameter, and then run the specified container image file (the image file here is generally a script file, which describes the steps to create a rootfs file system (i.e., root file system)), create rootfs under the directory with the container name, and set the directory as the container root directory. After that, the container will run with this directory as the root directory, and the reading and writing of files during the container operation are based on this directory as the root. A container is an independent operating environment, equivalent to a lightweight virtual machine, and the container root directory is equivalent to the virtual disk of the virtual machine. The size of the virtual disk is specified by the container quota parameter specified when creating the container. The disk limit on the container is ultimately achieved by limiting the directory size. The traditional approach is to use linuxquota to limit the size of a directory (such as Figure 2 shown).

[0047] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0048] Creates an empty virtual disk file of a preset size.

[0049] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0050] A virtual disk file of a preset size is created by using a sparse file technology and attribute information of the virtual disk file is set.

[0051] The setting of the attribute information of the virtual disk file includes setting the end position of the file.

[0052] In an exemplary embodiment, after creating a virtual disk of preset capacity and before mounting the virtual disk to the root file system directory, the method further includes:

[0053] The virtual disk file is formatted and a first file system is established.

[0054] In an exemplary embodiment, the first file system includes a second generation extended ext2 file system, or a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

[0055] In S11, if the container name is ContainerA, the created root directory is / ContainerA.

[0056] In S12, a virtual disk can be created by creating an empty virtual disk file of a preset size, formatting the virtual disk file, and establishing an ext2 file system. For example: create an empty virtual disk file rootfs.img (rootfs.img is the file name and can be specified arbitrarily) of 512M size through "dd if= / dev / zero of=rootfs.imgbs=1M count=512"; format the virtual disk file through "mkfs.ext2 rootfs.img" and establish a second-generation extended ext2 file system. In some other embodiments, a third-generation extended ext3 file system or a fourth-generation extended ext4 file system can also be established.

[0057] In S12, a virtual disk can also be created by "dd if= / dev / zero of=rootfs.img bs=1M count=0seek=512". Since a sparse file does not actually occupy space after creation, the end position of the file is set only by seek*bs (for example, 521*1M is the 512M offset as the end of the file). This utilizes the sparse file characteristics to optimize the virtual disk creation process, greatly reducing the virtual disk creation time and thus reducing the container creation time. For example, the actual creation time of creating a virtual disk on a 1G Loongson development board through "dd if= / dev / zero of=rootfs.img bs=1M count=512" is about 3 minutes. This will cause the embedded device to be occupied by the virtual disk creation task for a long time, resulting in other tasks of the embedded device, such as temperature monitoring or tasks that need to be executed in a timely manner, not being responded to in a timely manner. The actual creation time of creating a virtual disk on a Loongson development board with a main frequency of 1G using "dd if= / dev / zero of=rootfs.img bs=1M count=0seek=512" is about 1 second.

[0058] In S12, for ease of management, a virtual disk may be created under the root directory (e.g., / container name / ). For example, the created empty virtual disk file is rootfs.img. Since it is created under the root directory, its path is " / container name / rootfs.img". Of course, a virtual disk may not be created under the root directory (e.g., / container name / ), but the corresponding relationship between the container and the corresponding virtual disk needs to be recorded.

[0059] In S13, the created empty root file system directory may be a rootfs directory, that is, " / container name / rootfs". The directory with the same name as the container name is the root directory, which is mainly used to store the rootfs directory, virtual disk files, and other container configuration files. The rootfs directory under the root directory of the root file system directory is the root directory of the container after the container is run, that is, after the container is run, all processes in the container will use the rootfs directory as the root directory.

[0060] In S14, the created virtual disk can be mounted to the root file system directory. For example, the virtual disk file " / ContainerA / rootfs.img" can be mounted to " / ContainerA / rootfs" by running "mount -o loop -w rootfs.img ContainerA / rootfs".

[0061] In S15, after the virtual disk is mounted, a root file system can be created under the root file system directory. At this time, the path of the root file system is / ContainerA / rootfs / . Creating a root file system means copying operating system files and creating a series of configuration files according to the instructions in the container image file.

[0062] The embodiment of the present application realizes a general container quota restriction function by mounting the created virtual disk of preset capacity to the root file system directory, and optimizes the virtual disk creation process by utilizing the sparse file characteristics, thereby greatly reducing the virtual disk creation time and thus reducing the container creation time.

[0063] Figure 3 Schematic diagram of a container creation device according to an embodiment of the present application, such as Figure 3 As shown, the container creation device of this embodiment includes a memory and a processor, wherein the memory is used to store a program for container creation; the processor is used to read and execute the program for container creation, and performs the following operations:

[0064] Create the root directory of the container to be created;

[0065] Create a virtual disk with preset capacity;

[0066] Creating an empty root file system directory under the root directory;

[0067] Mounting the virtual disk to the root file system directory;

[0068] A root file system is created under the root file system directory.

[0069] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0070] Creates an empty virtual disk file of a preset size.

[0071] In an exemplary embodiment, the step of creating a virtual disk of a preset capacity includes:

[0072] A virtual disk file of a preset size is created by using a sparse file technology and attribute information of the virtual disk file is set.

[0073] In an exemplary embodiment, the processor is used to read and execute the program for container creation, and further performs the following operations:

[0074] The virtual disk file is formatted and a first file system is established.

[0075] In an exemplary embodiment, the first file system includes a second generation extended ext2 file system, or a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

[0076] The embodiment of the present application realizes a general container quota restriction function by mounting the created virtual disk of preset capacity to the root file system directory, and optimizes the virtual disk creation process by utilizing the sparse file characteristics, thereby greatly reducing the virtual disk creation time and thus reducing the container creation time.

[0077] The present application describes multiple embodiments, but the description is exemplary rather than restrictive, and it is obvious to those skilled in the art that there may be more embodiments and implementations within the scope of the embodiments described in the present application. Although many possible feature combinations are shown in the drawings and discussed in the specific embodiments, many other combinations of the disclosed features are also possible. Unless specifically limited, any feature or element of any embodiment may be used in combination with any other feature or element in any other embodiment, or may replace any other feature or element in any other embodiment.

[0078] The present application includes and contemplates combinations of features and elements known to those of ordinary skill in the art. The embodiments, features and elements disclosed in the present application may also be combined with any conventional features or elements to form a unique invention scheme defined by the claims. Any features or elements of any embodiment may also be combined with features or elements from other invention schemes to form another unique invention scheme defined by the claims. Therefore, it should be understood that any feature shown and / or discussed in the present application may be implemented individually or in any appropriate combination. Therefore, except for the limitations made according to the attached claims and their equivalents, the embodiments are not subject to other restrictions. In addition, various modifications and changes may be made within the scope of protection of the attached claims.

[0079] In addition, when describing representative embodiments, the specification may have presented the method and / or process as a specific sequence of steps. However, to the extent that the method or process does not rely on the specific order of the steps described herein, the method or process should not be limited to the steps of the specific order described. As will be understood by those of ordinary skill in the art, other sequences of steps are also possible. Therefore, the specific sequence of the steps set forth in the specification should not be interpreted as a limitation to the claims. In addition, the claims for the method and / or process should not be limited to the steps of performing them in the order written, and those skilled in the art can easily understand that these sequences can be changed and still remain within the spirit and scope of the embodiments of the present application.

[0080] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

Claims

1. A container creation method, characterized in that: Applied to a lightweight embedded platform, the method comprises: Create the root directory of the container to be created; Create a virtual disk with preset capacity; Creating an empty root file system directory under the root directory; Mounting the virtual disk to the root file system directory; Creating a root file system under the root file system directory; The step of creating a virtual disk of preset capacity includes: By using the dd command to create an empty virtual disk file of a preset size; or, A virtual disk file of a preset size is created by using the dd command and sparse file technology, and attribute information of the virtual disk file is set.

2. The container creation method according to claim 1, after creating a virtual disk of preset capacity and before mounting the virtual disk to the root file system directory, further comprising: The virtual disk file is formatted and a first file system is established.

3. The container creation method according to claim 2, comprising: The first file system includes a second generation extended ext2 file system, a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

4. A container creation device, comprising a memory and a processor, characterized in that: Applied to lightweight embedded platforms; The memory is used to store a program for creating a container; The processor is configured to read and execute the program for creating a container, and perform the following operations: Create the root directory of the container to be created; Create a virtual disk with preset capacity; Creating an empty root file system directory under the root directory; Mounting the virtual disk to the root file system directory; Creating a root file system under the root file system directory; The step of creating a virtual disk of preset capacity includes: By using the dd command to create an empty virtual disk file of a preset size; or, A virtual disk file of a preset size is created by using the dd command and sparse file technology, and attribute information of the virtual disk file is set.

5. The container creation device according to claim 4, wherein the processor is configured to read and execute the program for container creation, and further perform the following operations: The virtual disk file is formatted and a first file system is established.

6. The container creation device according to claim 5, characterized in that: The first file system includes a second generation extended ext2 file system, a third generation extended ext3 file system, or a fourth generation extended ext4 file system.

Citation Information

Patent Citations

  • Method and apparatus for managing container image

    CN110308972A

  • Method and device for mounting host directory into container environment

    CN110888852A

  • Method, device and equipment convenient for container instance scheduling and storage medium

    CN111367615A