Container handling methods, apparatus and electronic equipment

By storing image data in a distributed file system and using lightweight images to start containers, the problem of low startup efficiency caused by image distribution is solved, and fast and efficient container startup is achieved.

CN123114499APending Publication Date: 2026-11-17LENOVO (BEIJING) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611339395.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-31
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In existing technologies, the container startup efficiency decreases as the image data volume continues to increase during the image distribution process.

Method used

The data of each directory in the first image is stored in the second directory of the target distributed file system. The target container is started based on the lightweight second image, and the target environment variables are configured in the target container. The container can be started quickly by switching the root directory and configuring the environment variables.

Benefits of technology

It improves container startup speed, reduces image distribution time, enhances container startup efficiency, and is not limited by image size.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114499A_ABST
    Figure CN123114499A_ABST
Patent Text Reader

Abstract

This application discloses a container processing method, apparatus, and electronic device. The container processing method includes: obtaining a first image corresponding to a target container; storing the data of each first directory in the first image into a second directory in a target distributed file system; starting the target container based on the second image, wherein the data volume of the second image is less than the data volume of the first image; determining the target environment variables required by the target container; switching the root directory of the target container to the second directory; and configuring the target environment variables in the target container.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a container processing method, apparatus and electronic device. Background Technology

[0002] In container orchestration systems, the persistence of the container's runtime environment is typically achieved through an image distribution process. This involves first saving the image, which includes the runtime environment, and then pulling the saved image the next time the container is started. However, as users modify and save the image multiple times, the image's data size increases continuously, leading to an excessively long image distribution process and reducing container startup efficiency. Summary of the Invention

[0003] This application provides a container processing method, including: obtaining a first image corresponding to the target container; storing the data of each first directory in the first image into a second directory in a target distributed file system; starting the target container based on a second image, wherein the data volume of the second image is less than the data volume of the first image; determining the target environment variables required by the target container; switching the root directory of the target container to the second directory; and configuring the target environment variables in the target container.

[0004] In some embodiments, after configuring the target environment variable in the target container, the method further includes: obtaining user modification data of the target container; and saving the modification data to the second directory based on the root directory.

[0005] In some embodiments, after storing the data of each first directory in the first image into a second directory in the target distributed file system, the method further includes: recording the second directory into the database of the runtime management system based on the target runtime corresponding to the target distributed file system, wherein the second directory is obtained from the database when the target container is restarted.

[0006] In some embodiments, before storing the data of each first directory in the first image into a second directory in a target distributed file system, the method further includes: starting an initialization container based on the first image; and extracting the data of each first directory from the first image in the initialization container.

[0007] In some embodiments, extracting data from each of the first directories from the first image in the initialization container includes: decompressing the first image in the initialization container to obtain decompressed data; and obtaining data from each of the first directories based on the decompressed data.

[0008] In some embodiments, the method further includes: issuing a target prompt message if starting the initialization container based on the first image fails.

[0009] In some embodiments, determining the target environment variables required for the target container includes: determining the environment configuration, driver path, and device path in the target container; and determining the target environment variables based on the environment configuration, the driver path, and the device path.

[0010] In some embodiments, switching the root directory of the target container to the second directory includes: determining that the second image is mounted as the system directory of the root directory, unmounting the system directory; and mounting the second directory as the root directory.

[0011] This application embodiment also provides a container processing apparatus, including: a storage module, configured to obtain a first image corresponding to the target container, and store the data of each first directory in the first image into a second directory in a target distributed file system; a startup module, configured to start the target container based on a second image, wherein the data volume of the second image is less than the data volume of the first image; a determination module, configured to determine the target environment variables required by the target container; and a switching module, configured to switch the root directory of the target container to the second directory, and configure the target environment variables in the target container.

[0012] This application also provides an electronic device, including: a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to: obtain a first image corresponding to the target container; store the data of each first directory in the first image into a second directory in a target distributed file system; start the target container based on a second image, wherein the data volume of the second image is less than the data volume of the first image; determine the target environment variables required by the target container; switch the root directory of the target container to the second directory; and configure the target environment variables in the target container. Attached Figure Description

[0013] To more clearly illustrate the technical solutions of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0014] Figure 1 A flow chart of a container processing method according to an embodiment of this application. Figure 1 ; Figure 2 A flow chart of a container processing method according to an embodiment of this application. Figure 2 ; Figure 3 A flow chart of a container processing method according to an embodiment of this application. Figure 3 ; Figure 4 This is a flowchart illustrating the determination of target environment variables in an embodiment of this application; Figure 5 This is a flowchart illustrating the process of switching the root directory to the second directory according to an embodiment of this application. Figure 6 This is a schematic diagram of a container processing method according to an embodiment of this application; Figure 7 This is a timing diagram of the initial startup of the target container according to an embodiment of this application; Figure 8 This is a timing diagram for restarting the target container according to an embodiment of this application; Figure 9 This is a structural block diagram of a container processing apparatus according to an embodiment of this application; Figure 10 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation

[0015] Various embodiments and features of this application are described herein with reference to the accompanying drawings.

[0016] It should be understood that various modifications can be made to the embodiments described herein. Therefore, the above description should not be considered as limiting, but merely as an example of embodiments. Other modifications within the scope and spirit of this application will be apparent to those skilled in the art.

[0017] The accompanying drawings, which are included in and form part of this specification, illustrate embodiments of the present application and, together with the general description of the present application given above and the detailed description of the embodiments given below, serve to explain the principles of the present application.

[0018] These and other features of this application will become apparent from the following description of preferred forms of embodiments given as non-limiting examples, with reference to the accompanying drawings.

[0019] It should also be understood that although this application has been described with reference to some specific examples, those skilled in the art can certainly implement many other equivalent forms of this application.

[0020] The above and other aspects, features and advantages of this application will become more apparent when taken in conjunction with the accompanying drawings and in view of the following detailed description.

[0021] Specific embodiments of this application are described thereafter with reference to the accompanying drawings; however, it should be understood that the claimed embodiments are merely examples of this application, which can be implemented in various ways. Well-known and / or repeated functions and structures are not described in detail to avoid unnecessary or redundant details that could obscure the application. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but merely serve as the basis and representative basis for the claims to teach those skilled in the art to use this application in a variety of substantially any suitable detailed structures.

[0022] This specification may use the phrases “in one embodiment,” “in another embodiment,” “in yet another embodiment,” or “in other embodiments,” all of which may refer to one or more of the same or different embodiments according to this application.

[0023] This application provides a container processing method that stores the data of each first directory in a first image into a second directory in a target distributed file system. A target container is started based on the lightweight second image. The target environment variables required by the target container are determined, the root directory of the target container is switched to the second directory, and the target environment variables are configured within the target container. This solution enables the target container to be started again simply by pulling the lightweight second image, switching the root directory, and configuring the environment variables, based on the target distributed file system. This eliminates the need for an image distribution process, making the container startup speed independent of image size. While persisting the container's runtime environment, it also improves the container's startup efficiency.

[0024] like Figure 1 As shown, the container processing method includes the following steps: Step S101: Obtain the first image corresponding to the target container, and store the data of each first directory in the first image into the second directory in the target distributed file system.

[0025] In this embodiment, the target container can be a container in a container orchestration system, such as Kubernetes, Docker Swarm, or Apache Mesos. The first image can be a runtime image of the target container, which includes the runtime environment of the target container. The first image can be obtained from an image repository in response to a user's startup command for the target application, and the target application can run in the target container.

[0026] The first image includes multiple first directories, each forming a file system within the first image. These first directories may include, for example, ` / bin`, ` / sbin`, ` / lib` & ` / lib64`, ` / usr`, ` / var`, ` / tmp`, ` / root`, etc. The target distributed file system can be a system for sharing and storing data across multiple computers or servers, allowing multiple nodes to work collaboratively over a network to achieve redundant data storage, high availability, and load balancing. Second directories are pre-defined within the target distributed file system (DFS). Data from each first directory can be extracted from the first image and stored in the second directory.

[0027] Step S102: Start the target container based on the second image, where the data volume of the second image is less than that of the first image.

[0028] In this embodiment, the data size of the second image is smaller than that of the first image. The second image can be a lightweight base image. The base image is the minimal base image file that serves as the underlying starting point when building a custom image, and it is the root image of all upper-level images. The second image can be obtained from an image repository, and the target container can be started based on the second image through a Working pod in the container orchestration system.

[0029] Step S103: Determine the target environment variables required for the target container.

[0030] In this embodiment, environmental analysis can be performed on the target container to determine the target environment variables required by the target container. The target environment variables can characterize the behavior of the target container at runtime. For example, the target environment variables may include database address, API key, application running mode, listening port, log level, etc.

[0031] Step S104: Switch the root directory of the target container to the second directory and configure the target environment variables in the target container.

[0032] In this embodiment, the root directory of the target container is the top-level directory of the internal file system of the target container, which can be represented as / , and is the starting point of all files and directories within the target container. The root directory of the target container is switched to the second directory, and the target environment variables are configured within the target container to complete the startup of the target container. Since the data of each directory in the first image has already been stored in the second directory of the distributed file system, when starting the target container again, only the lightweight second image needs to be pulled for root directory switching and environment variable configuration, without needing to perform the image distribution process again, thereby improving container startup speed.

[0033] The container processing method of this application embodiment obtains a first image corresponding to the target container, stores the data of each first directory in the first image into a second directory in the target distributed file system; starts the target container based on the second image, where the data size of the second image is smaller than that of the first image; determines the target environment variables required by the target container; switches the root directory of the target container to the second directory, and configures the target environment variables in the target container. This solution enables the target container to be started again by simply pulling a lightweight second image, switching the root directory, and configuring environment variables, thus eliminating the need for an image distribution process. This allows the container's startup speed to be unrestricted by the image size, improving startup efficiency while persisting the container's runtime environment. Furthermore, the maximum number of layers in an image repository is typically 128. This solution, by switching the root directory of the target container to the second directory of the target distributed file system, allows for the storage of image data without being limited by the number of image layers.

[0034] In some embodiments of this application, after configuring the target environment variable in the target container, such as Figure 2 As shown, it also includes the following steps: Step S105: Obtain the user's modification data for the target container.

[0035] In this embodiment, the user's modifications to the target container may include one or more of the following: modifications to application configuration files, business data, log files, environment variables, startup parameters, etc.

[0036] Step S106: Save the modified data to the second directory based on the root directory.

[0037] In this embodiment, since the root directory has been switched to the second directory in the distributed file system, user modifications to the target container will be directed to the second directory. Modified data is sent to the second directory based on the root directory for storage.

[0038] This method saves modified data to a second directory via the root directory, allowing changes to the target container to be stored in the target distributed file system. This synchronizes the data in the target distributed file system with the target container's actual runtime environment. Upon the next startup of the target container and a change of root directory, the target container restores the latest runtime environment. Furthermore, it allows for saving modified data without being limited by the number of image storage layers, improving flexibility.

[0039] In some embodiments of this application, after storing the data of each first directory in the first image into a second directory in the target distributed file system, the method further includes: Based on the target runtime corresponding to the target distributed file system, the second directory is recorded in the database of the runtime management system, wherein the second directory is obtained from the database when the target container is restarted.

[0040] In this embodiment, the target runtime is responsible for starting, stopping, and managing the target distributed file system at the operating system level. The runtime management system is used to manage the runtimes of the target runtime and the target container, such as performing runtime lifecycle management, distributing runtime configuration data, monitoring runtime status, security and compliance control, and scheduling multiple runtimes.

[0041] After storing the data of each first directory in the first image into the second directory, the target runtime records the second directory into the database of the runtime management system. When the target container is started again, it can first start the target container based on the second image, determine the target environment variables required by the target container, then obtain the second directory from the database, switch the root directory of the target container to the second directory, and configure the target environment variables in the target container to complete the startup of the target container.

[0042] This allows the target container to record the second directory into the runtime management system's database during runtime. When the target container is restarted, the root directory of the target container can be switched based on the second directory obtained from the database, thereby efficiently and reliably restoring the target container's runtime environment.

[0043] In some embodiments of this application, before storing the data of each first directory in the first image into a second directory in the target distributed file system, such as Figure 3 As shown, it also includes the following steps: Step S107: Start and initialize the container based on the first image.

[0044] In this embodiment, the initialization container is a container in the container orchestration system. The initialization container can be started based on the first image through the working pod in the container orchestration system.

[0045] Step S108: Extract data from each of the first directories from the first image in the initialization container.

[0046] In this embodiment, data is extracted from each first directory of the first image in the initialization container to obtain the data of each first directory.

[0047] By initializing the container, the data extraction process of each first directory is made more in line with the operating environment under the container orchestration system. Furthermore, initializing the container can provide a closed environment, thereby improving the security and stability of the data extraction process of each first directory.

[0048] In some embodiments of this application, the step of extracting data from each of the first directories in the initialization container includes: The first image is decompressed in the initialization container to obtain decompressed data; Data for each of the first directories is obtained based on the decompressed data.

[0049] In this embodiment, the first image can be decompressed within the initialization container using a decompression tool to obtain decompressed data. The decompression tool can be, for example, WinRAR, 7-Zip, or WinZip. The decompressed data includes data from each of the first directories, which is then obtained from the decompressed data. Optionally, the first image can be decompressed to the local machine first, and then the obtained decompressed data can be sent to the second directory. Alternatively, the target path for decompression can be set to the second directory, allowing the decompressed data to be stored directly in the second directory.

[0050] By decompressing the first image, data extraction can be completed directly in the environment of container initialization, thereby accurately and efficiently extracting data from each first directory from the first image.

[0051] It should be noted that the decompression method is only one specific implementation of extracting data from each first directory in this application embodiment. Those skilled in the art can also use other different methods to extract data from each first directory as needed, such as mounting the first image as a virtual optical drive, using DiskGenius for extraction, using UltraISO for extraction, etc. Other different methods are all within the protection scope of this application.

[0052] In some embodiments of this application, the container processing method further includes: If starting the initialization container based on the first image fails, a target prompt message will be issued.

[0053] In this embodiment, when starting the initialization container based on the first image, it is determined whether the initialization container has started successfully. If the start fails, a target prompt message is issued. The target prompt message may include the initialization container failing to start or being unable to start the initialization container, so as to remind the user to check.

[0054] Since the initialization container starts before the target container, if the initialization container fails to start, the step of starting the target container based on the second image can be skipped, thus avoiding unnecessary operations and saving computing resources.

[0055] In some embodiments of this application, the step of determining the target environment variables required for the target container is as follows: Figure 4 As shown, it includes the following steps: Step S1031: Determine the environment configuration, drive path, and device path in the target container.

[0056] In this embodiment, the environment configuration, driver path, and device path can be determined by performing environment analysis on the target container. The environment configuration can include context rules defined for the application within the target container to run, using environment variables, configuration files, and runtime parameters, to ensure consistency across development, testing, and production environments. The driver path can include the directory paths of hardware drivers and runtime library files accessible within the target container. The device path can include the paths to host machine hardware device nodes that can be directly accessed from within the target container.

[0057] Step S1032: Determine the target environment variable based on the environment configuration, the drive path, and the device path.

[0058] It can record environment configuration, driver path, and device path, and define the environment configuration, driver path, and device path as target environment variables.

[0059] By determining the environment configuration, driver path, and device path within the target container, the target environment variables are made more consistent with the runtime environment of the target container, thus improving the accuracy of the target environment variables.

[0060] In some embodiments of this application, the step of switching the root directory of the target container to the second directory is as follows: Figure 5 As shown, it includes the following steps: Step S1041: Determine that the second image is mounted as the system directory of the root directory, and unmount the system directory.

[0061] In this embodiment, after the target container is started based on the second image, the system directory of the second image is mounted as the root directory. Since it is necessary to switch the root directory to the second directory, the system directory is unloaded first.

[0062] Step S1042: Mount the second directory as the root directory.

[0063] By first unloading the system directory of the second image and then mounting the second directory as the root directory, the mount point is switched, thus reliably switching the root directory to the second directory.

[0064] In some embodiments of this application, after unloading the system directory, a new old system directory is created in the second image. This new old system directory can provide a temporary location to store the mount point of the old root file system, thereby completely unloading the system directory of the second image and completing the isolation of the container environment.

[0065] To further illustrate the technical concept of this application, the technical solution will now be explained in conjunction with specific application scenarios.

[0066] This application provides a container processing method, such as... Figure 6 and Figure 7 As shown, the process for starting the target container for the first time includes the following steps: The user sends a command to the runtime management system to start the target container. The runtime management system, through a Workingpod, starts an initialization container based on a runtime image (the first image) pulled from the image repository. Within this initialization container, the runtime image is decompressed, and the data from the decompressed first directories is stored in a second directory within the DFS (Target Distributed File System). The target runtime corresponding to the target distributed file system records this second directory in the runtime management system's database. Then, the runtime management system, through a Workingpod, starts the target container based on a lightweight base image (the second image) pulled from the image repository. By performing environmental analysis on the target container, the system determines the required target environment variables and the system directory of the lightweight base image. The system directory is unmounted, and the second directory is mounted as the root directory. Finally, the target environment variables are configured within the target container, completing the initial startup of the target container. Upon receiving modifications from the user to the target container, the changes are saved to the second directory.

[0067] like Figure 8 As shown, when the target container is restarted, the runtime management system starts the target container through the Working pod based on the lightweight base image pulled from the image repository. By performing environment analysis on the target container, the system determines the target environment variables required by the target container and the system directory of the lightweight base image. The system directory is unmounted, and the second directory is mounted as the root directory. Finally, the target environment variables are configured in the target container to complete the restart of the target container.

[0068] By applying the above technical solutions, when restarting the target container, it is only necessary to pull the lightweight base image, switch the root directory and configure the environment variables, and then start it based on the target distributed file system. This eliminates the need for an image distribution process, making the container startup speed unrestricted by the image size. While persisting the container runtime environment, it also improves the container startup efficiency.

[0069] This application also provides a container handling apparatus, such as... Figure 9As shown, it includes: a storage module, used to obtain a first image corresponding to the target container, and store the data of each first directory in the first image into a second directory in the target distributed file system; a startup module, used to start the target container based on the second image, wherein the data volume of the second image is less than the data volume of the first image; a determination module, used to determine the target environment variables required by the target container; and a switching module, used to switch the root directory of the target container to the second directory, and configure the target environment variables in the target container.

[0070] By applying the above technical solutions, when restarting the target container, only a lightweight second image needs to be pulled, the root directory needs to be switched, and the environment variables need to be configured. Then, it can be started based on the target distributed file system, thus eliminating the need for an image distribution process. This makes the container startup speed not limited by the image size, and improves the container startup efficiency while persisting the container runtime environment.

[0071] In specific application scenarios, the container processing device also includes a storage module, used to: obtain user modification data of the target container; and save the modification data to the second directory based on the root directory.

[0072] In specific application scenarios, the container processing device further includes a recording module, used to: record the second directory to the database of the runtime management system based on the target runtime corresponding to the target distributed file system, wherein the second directory is obtained from the database when the target container is restarted.

[0073] In specific application scenarios, the container processing module also includes an extraction module, used to: start an initialization container based on the first image; and extract data from each of the first directories from the first image in the initialization container.

[0074] In a specific application scenario, the extraction module is specifically used to: decompress the first image in the initialization container to obtain decompressed data; and obtain data for each of the first directories based on the decompressed data.

[0075] In specific application scenarios, the container processing module also includes a prompting module, which is used to issue a target prompt message if the initialization container fails to start based on the first image.

[0076] In specific application scenarios, the determination module is specifically used to: determine the environment configuration, driver path, and device path in the target container; and determine the target environment variables based on the environment configuration, driver path, and device path.

[0077] In specific application scenarios, the switching module is specifically used to: determine that the second image is mounted as the system directory of the root directory, unmount the system directory; and mount the second directory as the root directory.

[0078] This application also provides an electronic device, such as... Figure 10 As shown, it includes: a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to: obtain a first image corresponding to the target container; store the data of each first directory in the first image into a second directory in the target distributed file system; start the target container based on a second image, wherein the data volume of the second image is less than the data volume of the first image; determine the target environment variables required by the target container; switch the root directory of the target container to the second directory; and configure the target environment variables in the target container.

[0079] The electronic device in this application embodiment can be a terminal, or it can be any other device besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, handheld computer, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. The embodiments disclosed in this disclosure do not impose specific limitations.

[0080] The memory may include RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0081] The processors mentioned above can be general-purpose processors, including CPUs, NPs (Network Processors), etc.; they can also be DSPs (Digital Signal Processors), ASICs (Application Specific Integrated Circuits), FPGAs (Field Programmable Gate Arrays), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0082] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.

[0083] The above embodiments are merely exemplary embodiments of this application and are not intended to limit this application. The scope of protection of this application is defined by the claims. Those skilled in the art can make various modifications or equivalent substitutions to this application within its substance and scope of protection, and such modifications or equivalent substitutions should also be considered to fall within the scope of protection of this application.

Claims

1. A container handling method, comprising: Obtain the first image corresponding to the target container, and store the data of each first directory in the first image into the second directory in the target distributed file system; The target container is started based on the second image, where the data size of the second image is smaller than that of the first image. Determine the target environment variables required for the target container; Switch the root directory of the target container to the second directory, and configure the target environment variables in the target container.

2. The container processing method as described in claim 1, further comprising, after configuring the target environment variable in the target container: Obtain the user's modification data for the target container; The modified data is saved to the second directory based on the root directory.

3. The container processing method as described in claim 1, further comprising, after storing the data of each first directory in the first image into a second directory in the target distributed file system: Based on the target runtime corresponding to the target distributed file system, the second directory is recorded in the database of the runtime management system, wherein the second directory is obtained from the database when the target container is restarted.

4. The container processing method as described in claim 1, further comprising, before storing the data of each first directory in the first image into a second directory in the target distributed file system: Start and initialize the container based on the first image; Data for each of the first directories is extracted from the first image in the initialization container.

5. The container processing method as described in claim 4, wherein extracting data from each of the first directories from the first image in the initialization container comprises: The first image is decompressed in the initialization container to obtain decompressed data; Data for each of the first directories is obtained based on the decompressed data.

6. The container processing method as described in claim 4, further comprising: If starting the initialization container based on the first image fails, a target prompt message will be issued.

7. The container processing method as described in claim 1, wherein determining the target environment variables required for the target container includes: Determine the environment configuration, driver path, and device path within the target container; The target environment variable is determined based on the environment configuration, the drive path, and the device path.

8. The container processing method as described in claim 1, wherein switching the root directory of the target container to the second directory includes: Determine that the second image is mounted to the system directory of the root directory, and unmount the system directory; Mount the second directory as the root directory.

9. A container handling apparatus, comprising: The storage module is used to obtain a first image corresponding to the target container and store the data of each first directory in the first image into a second directory in the target distributed file system. A startup module is used to start the target container based on a second image, wherein the data size of the second image is smaller than the data size of the first image. The determination module is used to determine the target environment variables required by the target container; A switching module is configured to switch a root directory of the target container to the second directory, and configure the target environment variable in the target container.

10. An electronic device comprising: A memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement: obtaining a first image corresponding to the target container, and storing data of each first directory in the first image into a second directory in a target distributed file system; starting the target container based on a second image, wherein a data amount of the second image is less than a data amount of the first image; determining a target environment variable required by the target container; switching a root directory of the target container to the second directory, and configuring the target environment variable in the target container.