CN113190325A - Container creation method and device - Google Patents

Container creation method and device Download PDF

Info

Publication number
CN113190325A
CN113190325A CN202110383555.9A CN202110383555A CN113190325A CN 113190325 A CN113190325 A CN 113190325A CN 202110383555 A CN202110383555 A CN 202110383555A CN 113190325 A CN113190325 A CN 113190325A
Authority
CN
China
Prior art keywords
creating
virtual disk
file system
container
root
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110383555.9A
Other languages
Chinese (zh)
Inventor
王俊
樊兆均
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Datang Microelectronics Technology Co Ltd
Original Assignee
Datang Microelectronics Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Datang Microelectronics Technology Co Ltd filed Critical Datang Microelectronics Technology Co Ltd
Priority to CN202110383555.9A priority Critical patent/CN113190325A/en
Publication of CN113190325A publication Critical patent/CN113190325A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45562Creating, deleting, cloning virtual machine instances

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a container creating method and a device, wherein the method comprises the following steps: creating a root directory of a container to be created; creating 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; and creating a root file system under the root file system directory. The container creation method and device disclosed by the application realize a universal container quota limiting function.

Description

Container creation method and device
Technical Field
The present disclosure relates to computer technologies, and in particular, to a container creation method and apparatus.
Background
Since the docker container technology is heavier for the embedded platform, the container in the embedded environment is mainly Linux LXC, and the Linux kernel of the embedded platform is often reduced (for example, the Alpine Linux kernel only has several megabytes), so that most high-level functions (for example, quota function) of Linux are not available, and thus there is no universal container quota limiting scheme on the embedded platform.
Disclosure of Invention
The application provides a container creation method which can realize a universal container quota limiting function.
The application provides a container creation method, which comprises the following steps:
creating a root directory of a container to be created;
creating 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;
and creating a root file system under the root file system directory.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
and creating an empty virtual disk file with a preset size.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
In an exemplary embodiment, after creating the virtual disk with the preset capacity and before mounting the virtual disk to the root file system directory, the method further includes:
and formatting the virtual disk file, and establishing a first file system.
In an exemplary embodiment, the method includes:
the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system or a fourth generation extension ext4 file system.
The application provides a container creation apparatus, comprising a memory and a processor,
the memory is used for storing a program for creating a container;
the processor is configured to read and execute the program for creating the container, and perform the following operations:
creating a root directory of a container to be created;
creating 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;
and creating a root file system under the root file system directory.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
and creating an empty virtual disk file with a preset size.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
In an exemplary embodiment, the processor is configured to read and execute the program for container creation, and further perform the following operations:
and formatting the virtual disk file, and establishing a first file system.
In an exemplary embodiment, the method comprises:
the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system or a fourth generation extension ext4 file system.
According to the embodiment of the application, the created virtual disk with the preset capacity is mounted to the root file system directory, so that a universal container quota limiting function is realized.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the application. Other advantages of the present application may be realized and attained by the instrumentalities and combinations particularly pointed out in the specification and the drawings.
Drawings
The accompanying drawings are included to provide an understanding of the present disclosure and are incorporated in and constitute a part of this specification, illustrate embodiments of the disclosure and together with the examples serve to explain the principles of the disclosure and not to limit the disclosure.
FIG. 1 is a schematic illustration of a container creation method of an embodiment of the present application;
FIG. 2 is a diagram illustrating a container creation method with a disk quota in the prior art;
FIG. 3 is a schematic view of a container creation apparatus of an embodiment of the present application;
Detailed Description
Fig. 1 is a schematic diagram of a container creation method according to an embodiment of the present application, and as shown in fig. 1, the container creation method according to the embodiment includes steps S11-S14:
s11, creating a root directory of the container to be created.
And S12, creating a virtual disk with preset capacity.
S13, creating an empty root file system directory under the root directory;
s14, mounting the virtual disk to the root file system directory;
and S15, creating a root file system under the root file system directory.
The container creation process creates a directory of the same name according to the specified container name parameter, then runs the specified container image file (here, the image file is generally a script file describing the steps of creating a rootfs file system (i.e., root file system)), creates rootfs under the container name directory, and sets the directory as a container root directory, and then the container operation runs with the directory as the root directory, and the reading and writing of the file in the container operation are performed based on the directory as the root. A container is an independent running environment and is equivalent to a lightweight virtual machine, and a container root directory is equivalent to a virtual disk of the virtual machine. The virtual disk size is specified by a container quota parameter specified when the container is created, and the disk limitation of the container is finally realized by limiting the directory size. The traditional approach is to use linux quota to limit the size of a directory (as shown in fig. 2).
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
and creating an empty virtual disk file with a preset size.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
The attribute information for setting the virtual disk file comprises a file end position.
In an exemplary embodiment, after creating the virtual disk with the preset capacity and before mounting the virtual disk to the root file system directory, the method further includes:
and formatting the virtual disk file, and establishing a first file system.
In an exemplary embodiment, the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system, or a fourth generation extension ext4 file system.
In S11, if the container name is ContainerA, the root directory created is/ContainerA.
In S12, a virtual disk may be created by creating an empty virtual disk file of a preset size, formatting the virtual disk file, and creating an ext2 file system. For example: creating an empty virtual disk file rootfs.img (rootfs.img is a file name, which can be arbitrarily specified) with a size of 512M by "dd if/dev/zero of rootfs.img bs-1M count-512"; the virtual disk file is formatted through mkfs.ext2 rootfs.img', and a second generation extension ext2 file system is established. In other embodiments, a third generation extension ext3 file system or a fourth generation extension ext4 file system may also be established.
In S12, a virtual disk may be created by "dd if/dev/zero of rootfs, img bs is 1 mcount, 0seek is 512", and since the sparse file is created without actually occupying space, the file end position is set by seek bs (for example, 521 × 1M is the offset of 512M as the file end), so that the virtual disk creation process is optimized by using the sparse file characteristic, and the virtual disk creation time is greatly reduced, thereby reducing the container creation time. For example, the virtual disk actual measurement creation time created on the Loongson development board with the dominant frequency of 1G is about 3 minutes by "dd if/dev/zero of rootfs.img bs is 1M count 512", which may cause the embedded device to be occupied by the virtual disk creation task for a long time and cause other tasks of the embedded device, such as temperature monitoring or tasks that need to be executed in time, not to get a timely response. And the actual measurement creation time of the virtual disk is about 1 second by "dd if/dev/zero of ro, i.e. img bs-1M count-0 seek-512" on the Loongson development board of the main frequency 1G.
In S12, for convenience of management, a virtual disk may be created under a root directory (e.g.,/container name /), for example, the created empty virtual disk file is rootfs. Of course, the virtual disk may not be created under the root directory (e.g.,/container name /), but the correspondence between the container and the corresponding virtual disk needs to be recorded.
In S13, the created empty root file system directory may be a rootfs directory, i.e., "/container name/rootfs". The directory with the same name as the container name is a root directory, and the root directory is mainly used for storing a rootfs directory, a virtual disk file and other container configuration files. The root file system directory is a rootfs directory under the root directory, the rootfs directory is a root directory which is operated as a container after the container is operated, namely, all processes in the container can regard the rootfs directory as the root directory after the container is operated.
In S14, the created virtual disk may be mounted to the root file system directory. For example, the virtual disk file "/continenara/rootfs.img" is mounted to "/continenara/rootfs" by running "mount-o loop-w rootfs.img ContainerA/rootfs".
At S15, after the virtual disk mount, a root file system may 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 is to copy operating system files and create a series of configuration files according to instructions in the container image file.
According to the embodiment of the application, the created virtual disk with the preset capacity is mounted to the root file system directory, a universal container quota limiting function is achieved, the virtual disk creating process is optimized by using the sparse file characteristics, and the virtual disk creating time is greatly shortened, so that the container creating time is shortened.
Fig. 3 is a schematic diagram of a container creation apparatus according to an embodiment of the present application, and as shown in fig. 3, the container creation apparatus according to the present embodiment includes a memory and a processor, where the memory is used for storing a program for creating a container; the processor is configured to read and execute the program for creating the container, and perform the following operations:
creating a root directory of a container to be created;
creating 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;
and creating a root file system under the root file system directory.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
and creating an empty virtual disk file with a preset size.
In an exemplary embodiment, the creating a virtual disk with a preset capacity includes:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
In an exemplary embodiment, the processor is configured to read and execute the program for container creation, and further perform the following operations:
and formatting the virtual disk file, and establishing a first file system.
In an exemplary embodiment, the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system, or a fourth generation extension ext4 file system.
According to the embodiment of the application, the created virtual disk with the preset capacity is mounted to the root file system directory, a universal container quota limiting function is achieved, the virtual disk creating process is optimized by using the sparse file characteristics, and the virtual disk creating time is greatly shortened, so that the container creating time is shortened.
The present application describes embodiments, but the description is illustrative rather than limiting and it will be apparent to those of ordinary skill in the art that many more embodiments and implementations are possible within the scope of the embodiments described herein. Although many possible combinations of features are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are possible. Any feature or element of any embodiment may be used in combination with or instead of any other feature or element in any other embodiment, unless expressly limited otherwise.
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 this application may also be combined with any conventional features or elements to form a unique inventive concept as defined by the claims. Any feature or element of any embodiment may also be combined with features or elements from other inventive aspects to form yet another unique inventive aspect, as defined by the claims. Thus, it should be understood that any of the features shown and/or discussed in this application may be implemented alone or in any suitable combination. Accordingly, the embodiments are not limited except as by the appended claims and their equivalents. Furthermore, various modifications and changes may be made within the scope of the appended claims.
Further, in describing representative embodiments, the specification may have presented the method and/or process as a particular sequence of steps. However, to the extent that the method or process does not rely on the particular order of steps set forth herein, the method or process should not be limited to the particular sequence of steps described. Other orders of steps are possible as will be understood by those of ordinary skill in the art. Therefore, the particular order of the steps set forth in the specification should not be construed as limitations on the claims. Further, the claims directed to the method and/or process should not be limited to the performance of their steps in the order written, and one skilled in the art can readily appreciate that the sequences may be varied and still remain within the spirit and scope of the embodiments of the present application.
It will be understood by those of ordinary skill in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those of ordinary skill in the art. Computer storage media includes, but is 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 tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies 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 includes any information delivery media as known to those skilled in the art.

Claims (10)

1. A method of creating a container, characterized in that,
creating a root directory of a container to be created;
creating 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;
and creating a root file system under the root file system directory.
2. The container creation method according to claim 1, wherein creating a virtual disk of a preset capacity includes:
and creating an empty virtual disk file with a preset size.
3. The container creation method according to claim 1, wherein creating a virtual disk of a preset capacity includes:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
4. The container creating method according to claim 2 or 3, wherein after creating the virtual disk with the preset capacity and before mounting the virtual disk to the root file system directory, the method further comprises:
and formatting the virtual disk file, and establishing a first file system.
5. The container creation method of claim 4, comprising:
the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system or a fourth generation extension ext4 file system.
6. A container creation apparatus comprising a memory and a processor, characterized in that:
the memory is used for storing a program for creating a container;
the processor is configured to read and execute the program for creating the container, and perform the following operations:
creating a root directory of a container to be created;
creating 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;
and creating a root file system under the root file system directory.
7. The container creation apparatus according to claim 6, said creating a virtual disk of a preset capacity comprising:
and creating an empty virtual disk file with a preset size.
8. The container creation apparatus according to claim 6, said creating a virtual disk of a preset capacity comprising:
creating a virtual disk file with a preset size through a sparse file technology and setting attribute information of the virtual disk file.
9. The container creation apparatus of claim 7 or 8, the processor configured to read and execute the program for container creation, and further configured to:
and formatting the virtual disk file, and establishing a first file system.
10. The container creation apparatus according to claim 9, wherein:
the first file system comprises a second generation extension ext2 file system, or a third generation extension ext3 file system or a fourth generation extension ext4 file system.
CN202110383555.9A 2021-04-09 2021-04-09 Container creation method and device Pending CN113190325A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110383555.9A CN113190325A (en) 2021-04-09 2021-04-09 Container creation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110383555.9A CN113190325A (en) 2021-04-09 2021-04-09 Container creation method and device

Publications (1)

Publication Number Publication Date
CN113190325A true CN113190325A (en) 2021-07-30

Family

ID=76975427

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110383555.9A Pending CN113190325A (en) 2021-04-09 2021-04-09 Container creation method and device

Country Status (1)

Country Link
CN (1) CN113190325A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116049896A (en) * 2023-03-29 2023-05-02 中孚安全技术有限公司 Method, system, equipment and medium for realizing data isolation under linux system
CN116257326A (en) * 2023-05-11 2023-06-13 安徽海马云科技股份有限公司 Method and device for managing storage space of container

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6615365B1 (en) * 2000-03-11 2003-09-02 Powerquest Corporation Storing a computer disk image within an imaged partition
JP2017120492A (en) * 2015-12-28 2017-07-06 キヤノンマーケティングジャパン株式会社 Information processing system, control method thereof, and program
CN110888852A (en) * 2019-11-11 2020-03-17 北京宝兰德软件股份有限公司 Method and device for mounting host machine catalog in container environment
CN111367615A (en) * 2018-12-26 2020-07-03 卓望数码技术(深圳)有限公司 Method, apparatus, device and storage medium facilitating container instance scheduling
CN111782339A (en) * 2020-06-28 2020-10-16 京东数字科技控股有限公司 Container creation method and device, electronic equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6615365B1 (en) * 2000-03-11 2003-09-02 Powerquest Corporation Storing a computer disk image within an imaged partition
JP2017120492A (en) * 2015-12-28 2017-07-06 キヤノンマーケティングジャパン株式会社 Information processing system, control method thereof, and program
CN111367615A (en) * 2018-12-26 2020-07-03 卓望数码技术(深圳)有限公司 Method, apparatus, device and storage medium facilitating container instance scheduling
CN110888852A (en) * 2019-11-11 2020-03-17 北京宝兰德软件股份有限公司 Method and device for mounting host machine catalog in container environment
CN111782339A (en) * 2020-06-28 2020-10-16 京东数字科技控股有限公司 Container creation method and device, electronic equipment and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116049896A (en) * 2023-03-29 2023-05-02 中孚安全技术有限公司 Method, system, equipment and medium for realizing data isolation under linux system
CN116257326A (en) * 2023-05-11 2023-06-13 安徽海马云科技股份有限公司 Method and device for managing storage space of container
CN116257326B (en) * 2023-05-11 2023-08-29 安徽海马云科技股份有限公司 Method and device for managing storage space of container

Similar Documents

Publication Publication Date Title
US9767035B2 (en) Pass-through tape access in a disk storage environment
CN113190325A (en) Container creation method and device
CN109976669B (en) Edge storage method, device and storage medium
US10223038B2 (en) File management in a file system
US9087014B1 (en) Tape backup and restore in a disk storage environment
CN110019063B (en) Method for computing node data disaster recovery playback, terminal device and storage medium
CN108572888B (en) Disk snapshot creating method and disk snapshot creating device
CN111581171A (en) Log processing method and device, computing equipment and medium
CN114153394A (en) Data storage management method, device and equipment
CN110764694B (en) Method and system for controlling storage space
CN110321077B (en) Method and device for managing centrally stored files
CN109445715B (en) Bad block processing method and device for combined block
US10902872B1 (en) Managing index writes to a tape medium
CN115328851A (en) Data protection method, device, equipment and medium
CN110932884B (en) Method and device for adding multiple networks to cloud physical machine
CN111813588A (en) Computer hard disk fault positioning method, device, equipment and storage medium
CN110287064B (en) Method and device for restoring disk data and electronic equipment
CN111858487A (en) Data updating method and device
CN108415814B (en) Method for automatically recording field change, application server and computer readable storage medium
CN112882659A (en) Information obtaining method and device, electronic equipment and storage medium
CN111309526A (en) File backup and recovery method and device
CN110688258A (en) Snapshot creating method and device
CN113900994B (en) File writing method and device
CN116303271A (en) Synchronous audio/video file processing method, device and medium for business client
US11625184B1 (en) Recalling files from tape

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination