Mirror image generation method, apparatus, device, medium, and program product

By monitoring lifecycle events in the container orchestration system and automatically triggering persistent tasks to generate images, the problem of low automation in image generation is solved, and the timely saving of container state and efficient image generation are achieved.

CN120848908BActive Publication Date: 2026-07-28MOORE THREADS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
MOORE THREADS TECH CO LTD
Filing Date
2025-09-18
Publication Date
2026-07-28

AI Technical Summary

Technical Problem

In existing technologies, the image generation process requires manual construction by technicians, resulting in low automation and susceptibility to errors due to human factors.

Method used

By monitoring container lifecycle events, persistent tasks are automatically triggered to save stopped containers as images, and the automatic generation of images is achieved by utilizing the container orchestration system's operators and persistent tasks.

Benefits of technology

It enables automated image generation, avoiding the tedious manual image building process, and ensures that images are saved promptly after containers stop running, thus improving the efficiency and accuracy of image generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120848908B_ABST
    Figure CN120848908B_ABST
Patent Text Reader

Abstract

The application discloses a mirror image generation method, device, equipment, medium and program product, and belongs to the technical field of containers. The method comprises the following steps: monitoring the working state of a first container during the running process of the first container; in response to the monitoring that the first container stops running, triggering a first persistence task; and saving the first container at the time of stopping running as a first mirror image by executing the first persistence task. That is, the mirror image generation process provided by the embodiment of the application automatically triggers a persistence task based on the stopping event of a container, and then generates a first mirror image. The method for automatically generating a mirror image provided by the embodiment of the application avoids the tedious operation of manually constructing a mirror image by a technician.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of container technology, and in particular to an image generation method, apparatus, device, medium, and program product. Background Technology

[0002] Container technology is a virtualization technology that encapsulates an application, its dependencies, and configuration files within a container, enabling the application to run in different computing environments. In related technologies, containers define their runtime environment through images.

[0003] In related technologies, images are usually created manually by technicians. Technicians will manually create a Dockerfile, which defines the method for building an application image from a base image. Then, the technicians will manually run the build command to generate an image based on the Dockerfile and push it to the image repository.

[0004] In related technologies, technicians often need to manually generate images. The process of manually generating images by technicians has a low degree of automation and is prone to errors due to human factors. Summary of the Invention

[0005] This application provides a method, apparatus, device, medium, and program product for generating images. The method for automatically generating images provided in the embodiments of this application avoids the tedious operation of manual image building by technicians.

[0006] According to one aspect of this application, a method for generating an image is provided, the method being performed by a computer device, the method comprising the following steps.

[0007] During the operation of the first container, monitor the working status of the first container;

[0008] In response to the detection that the first container has stopped running, the first persistent task is triggered;

[0009] By executing the first persistence task, the first container that has stopped running is saved as the first image.

[0010] According to one aspect of this application, an image generation apparatus is provided, the apparatus comprising the following modules.

[0011] The monitoring module is used to monitor the working status of the first container during its operation.

[0012] The triggering module is used to trigger the first persistent task in response to detecting that the first container has stopped running;

[0013] A generation module is used to save the first container that has stopped running as a first image by executing the first persistence task.

[0014] According to one aspect of this application, a computer device is provided, the computer device comprising: a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the image generation method as described above.

[0015] According to one aspect of this application, a computer-readable storage medium is provided that stores a computer program, which is loaded and executed by a processor to implement the image generation method described above.

[0016] According to one aspect of this application, a computer program product is provided, the computer program product storing a computer program that is loaded and executed by a processor to implement the image generation method as described above.

[0017] The beneficial effects of the technical solutions provided in this application include at least the following:

[0018] In this embodiment, when the first container is detected to have stopped running, a first persistence task is triggered. By executing the first persistence task, the stopped first container is automatically saved as a first image. This embodiment provides a method for automatically generating images, avoiding the tedious manual image building process for technicians. Furthermore, this embodiment deeply integrates the generation of the first image with the lifecycle events of the first container (specifically, the stop event), ensuring that the stopped first container is promptly saved after it stops running, and that the generation and updating of the first image are performed promptly. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments 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 of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a schematic diagram of an image generation method provided in one embodiment of this application.

[0021] Figure 2 This is a flowchart of an embodiment of the image generation method provided in this application.

[0022] Figure 3 This is a flowchart of a mirror generation method provided in another embodiment of this application.

[0023] Figure 4 This is a schematic diagram of a method for starting a first persistent task provided in an embodiment of this application.

[0024] Figure 5 This is a structural block diagram of a mirror generation apparatus provided in one embodiment of this application.

[0025] Figure 6 This is a structural block diagram of a computer device provided in one embodiment of this application. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0027] First, some terms used in the embodiments of this application will be introduced.

[0028] A container is a lightweight, isolated, and portable software runtime environment. It encapsulates an application, its dependencies, and configuration files, enabling the application to run in different computing environments. Unlike traditional virtual machines, containers isolate and allocate resources directly at the operating system level, meaning they are more lightweight and start up faster.

[0029] An image is a blueprint or template for a container, and a container is a running instance of that image. An image is a read-only file system that contains all the files and configurations needed to run a container. When an engineer wants to run an application on a machine, they can create a container instance based on an image.

[0030] Container orchestration systems are tools used to automate the management, deployment, and scaling of containerized applications. Technicians can use container orchestration systems to manage the lifecycle of containers. Optional container orchestration systems include Kubernetes (k8s) (an open-source container orchestration system), Docker Swarm (an officially provided container orchestration tool), Apache Mesos (an open-source distributed system kernel), Rancher (an enterprise-grade container management platform), and others.

[0031] Figure 1 A schematic diagram of an exemplary embodiment of the image generation method provided in this application is shown. Figure 1A container orchestration system 20 running on server cluster 10 is illustrated. The container orchestration system 20 may be Kubernetes. The container orchestration system 20 includes a master node 21 and multiple worker nodes. Schematic, the multiple worker nodes include worker node 22 and worker node 23. Optionally, each of the multiple worker nodes corresponds to an entity server in server cluster 10, and the master node 21 corresponds to an entity server in server cluster 10. Optionally, the master node 21 may also be deployed on the same entity server as a worker node.

[0032] like Figure 1 As shown, at least one container runs in each worker node, and worker node 22 runs a first container 101. The master node 21 provides multiple components, including an operator 102, which can be a Kubernetes Operator. The first container 101 also contains multiple components, including a first custom resource 103. The first custom resource 103 is a custom resource corresponding to the first container 101. Optionally, the first custom resource 103 can be a Kubernetes CRD (Custom Resource Definition). The first custom resource 103 stores the working state of the first container.

[0033] During the operation of the first container 101, the operator 102 will monitor the status of the first custom resource 103. When the status of the first custom resource 103 is detected as stopped, it indicates that the first container 101 has stopped running. At this time, the operator 102 will trigger the monitoring function 104 corresponding to the stop event. Optionally, the reason for the first container 101 stopping running may be that the user actively chooses to stop running the first container 101, or it may stop running in response to a failure in the operation of the first container 101, or it may stop running automatically in response to the current time reaching the preset stop time.

[0034] By triggering the monitoring function 104, the first persistence task 105 will be started. The first persistence task 105 will save the first container 106 that has stopped running as the first image 107. Optionally, the first persistence task 105 will also push the first image 107 to the first image repository 108 for storage. The first image repository 108 can be located in the cloud or in the local storage space of the physical server where the master node 21 is located. That is, this application embodiment provides a method for automatically generating images. When the first container stops running, the first persistence task saves the first container that has stopped running as the first image, avoiding the tedious operation of manually building images by technicians. Furthermore, this application embodiment deeply integrates the generation of the first image with the lifecycle event of the first container (specifically the stop event), ensuring that after the first container stops running, the first container that has stopped running can be saved in a timely manner, and the generation and updating of the first image can be performed in a timely manner.

[0035] In one embodiment, by executing a first persistence task, the running state of a stopped first container 106 is extracted, and the running state of the stopped first container 106 is encapsulated into a first image 107. Optionally, the running state includes at least one of file system information, environment variable information, runtime configuration information, and node information of the container orchestration system. In the above embodiment, by executing the first persistence task, the running state of the first container can be effectively saved, avoiding the loss of important running state data due to the first container crashing or stopping normally, thus enhancing the persistence capability of the first container's running state.

[0036] In the above embodiments, the image generation method is described as running on server cluster 10. In some embodiments, container orchestration system 20 may also be deployed on a server, or on a terminal device cluster, or on the same terminal device. This application does not limit this.

[0037] Figure 2 A flowchart of an image generation method provided in an exemplary embodiment of this application is shown, illustrated by way of example that the method is performed by a computer device, and the method includes the following steps.

[0038] Step 220: During the operation of the first container, monitor the working status of the first container;

[0039] In this embodiment, a first container will run on a computer device or other device. The first container encapsulates an application and all its dependencies and configuration files. Optionally, the first container corresponds to one application, or it may correspond to multiple applications. In this embodiment, the first container runs on an operating system and is isolated from other containers, but shares the same operating system kernel with them. In related technologies, containers are typically designed as stateless containers, meaning that after a container stops running, it does not automatically save its running state. If a container needs to save its running state, technicians need to manually write the running state to the container's external storage space (such as persistent volumes, databases, etc.).

[0040] In this embodiment, the first container is designed as a stateful container, and its running state will be persisted to prevent the loss of its running state data. Persistence refers to the operation of storing the running state data of the first container and maintaining the persistence of the running state data. For example, persistence operation is the operation of continuously storing the running state data of the first container.

[0041] In one embodiment, in response to receiving an image generation instruction, a computer device or other device runs a first container, whereby the goal of running the first container is to generate a new image. In another embodiment, the computer device runs the first container based on target requirements, meaning that the execution of the first container is triggered by target requirements and is not specifically for the purpose of generating a new image.

[0042] Step 240: In response to the detection that the first container has stopped running, the first persistent task is triggered;

[0043] In this embodiment, when the first container is detected to have stopped running, the computer device will trigger a designated task, namely a first persistence task. The persistence task is used to store the data in the first container and maintain the persistence of the data. For example, the persistence task is used to store the container data in the container's external storage space, so that even if the container is deleted or restarted, the container's data can still be retained.

[0044] The first persistence task is used to save the first stopped container as the first image. Specifically, the first persistence task is used to extract the running state of the first stopped container, encapsulate the running state into the first image, and optionally, the running state includes at least one of the following: file system information, environment variable information, runtime configuration information, and node information of the container orchestration system in which it is located.

[0045] In one embodiment, the triggering timing of the first persistence task includes at least one of the following:

[0046] First, in response to the detection that the first container has stopped running, the first persistent task is automatically triggered. That is, the triggering time of the first persistent task is tied to the stop event of the first container. If the first container is detected to have stopped running, the computer device will automatically trigger the first persistent task.

[0047] Second, in response to the detection that the first container has stopped running and the second image has reached its end-of-life time, the first persistence task is automatically triggered. The second image is the image used by the first container before it stopped running; that is, the second image is the image that the first container depended on before it stopped running. In this case, under the conditions that the first container has stopped running and the second image has reached its end-of-life time, the first persistence task will be automatically triggered to generate the first image. At this time, the inheritance and updating of the old image are realized.

[0048] Third, in response to the detection that the first container has stopped running, and at least one of the status information of the first container's running state meets the saving conditions, the first persistence task is automatically triggered. For example, if the node of the container orchestration system in which the first container is located changes, it indicates that the running state of the first container has changed significantly. In this case, the first container that has stopped running is saved as the first image. When the container is built and run again based on the first image, it can be done on the node of the changed container orchestration system.

[0049] Fourth, in response to the detection that the first container has stopped running and its runtime has reached the time threshold, the first persistence task is automatically triggered. In this case, the first persistence task will not be triggered if the first container is run briefly or accidentally. This avoids generating too many images, which would cause the image repository used to store images to become bloated and accumulate too many meaningless images.

[0050] This application deeply integrates the generation timing of the first image with the lifecycle events (specifically, the stop event) of the first container. This ensures that after the first container stops running, the stopped first container can be saved in a timely manner, and the generation and updating of the first image can be performed promptly, thus achieving an automated process. Furthermore, in addition to being associated with the stop event, the generation timing of the first image can also be combined with other conditions defined by the technicians, making the generation timing of the first image more flexible and better suited to specific use cases.

[0051] Step 260: By executing the first persistence task, the first container that has stopped running is saved as the first image.

[0052] By executing the first persistence task, the computer device saves the first container that has stopped running as the first image. That is, the embodiments of this application provide a method for automatically generating an image. When the first container stops running, the first persistence task saves the first container that has stopped running as the first image, avoiding the tedious operation of manually building the image by technicians.

[0053] In this embodiment, the first image is a new image generated by a computer device. The first image has the same function as an image created manually by a technician, and both can be used to create new container instances.

[0054] In one embodiment, a computer device pushes a first image to a first image repository by executing a first persistence task. The first image repository can be a local image repository on the computer device or a cloud image repository. Optionally, in the first image repository, the first image is used as an updated version of a second image. For example, a timestamp or specific tag is added to the first image, and the first image is set as the default image to be used the next time the first container starts. The second image is the image used by the first container before it stopped running; that is, the second image is the image that the first container depended on before it stopped running. Optionally, in the first image repository, the first image replaces the second image. For example, the tags of the second image are copied to the first image, and the second image is deleted to save storage space in the first image repository. In this embodiment, after the first image is generated, the first image is automatically managed, such as automatically replacing the second image or using the first image as an updated version of the second image. In this case, the management of the first image is performed automatically without the need for manual intervention by technical personnel, thereby reducing the labor costs required for image management.

[0055] In this embodiment, the first image is also pushed to the first image repository through a first persistent task, facilitating the use and management of the first image. When the first image is needed, it can be obtained directly from the first image repository, and when the first image needs to be managed, individual management of the first image can be achieved through unified management of multiple images in the first image repository.

[0056] Figure 3 This is a flowchart of an exemplary embodiment of the image generation method provided in this application, illustrated by an example of the method being executed by a computer device. The method includes the following steps.

[0057] Step 320: During the operation of the first container, monitor the working status of the first container;

[0058] In this embodiment, a first container will run on a computer device or other device. The first container encapsulates an application and all its dependencies and configuration files. Optionally, the first container corresponds to one application, or it may correspond to multiple applications. In one embodiment, during the operation of the first container, the computer device manages the lifecycle events of the first container through a container orchestration system.

[0059] Step 340: In response to the container orchestration system's operator detecting that the state of the first custom resource is stopped, the first persistent task is triggered;

[0060] In this embodiment, the container orchestration system provides an operator, and the system contains a first custom resource defined by an operator. This first custom resource corresponds to the first container. In response to the operator detecting that the first custom resource is in a stopped state, the computer device triggers a first persistent task. In another embodiment, in response to the controller in the operator of the container orchestration system detecting that the first custom resource is in a stopped state, the computer device triggers a first persistent task. In this embodiment, by monitoring the state of the first custom resource, the monitoring and management of the working state of the first container are indirectly achieved.

[0061] In this embodiment of the application, a container orchestration system is a system for managing the lifecycle events of a first container. Optionally, the container orchestration system is Kubernetes (k8s). The container orchestration system provides an operator, which is a tool specifically implemented within the container orchestration system for managing and automating specific resource objects. Optionally, the container orchestration system is Kubernetes, the operator is a Kubernetes Operator, and the controller is a Controller.

[0062] In one embodiment, the container orchestration system is Kubernetes, and the first custom resource is the first CRD (Custom Resource Definition). The CRD mechanism allows technicians to extend the API (Application Program Interface) of the container orchestration system, thereby allowing them to create and manage custom API objects. By defining CRDs, technicians can define their own resource types and provide storage, management, and automation capabilities for these resources. In this embodiment, technicians will set a corresponding first CRD for the first container to facilitate the management of the first container's lifecycle events. The monitored lifecycle state of the first CRD corresponds to the lifecycle state of the first container.

[0063] During the operation of the first container, the container orchestration system's operator monitors the status of the first custom resource. If the first custom resource is detected to be in a stopped state, it indicates that the first container has stopped running. In one embodiment, the container orchestration system's operator monitors the first custom resource at a preset monitoring frequency. Optionally, the monitoring frequency could be once per second, once every three seconds, once every five seconds, etc. Optionally, the specific monitoring frequency value can be designed by technicians based on actual operating conditions. For example, if the first container has experienced frequent stop events or its stop time is generally long during its historical operation, the monitoring frequency value can be designed to be a smaller value. In this case, the operator can more easily detect when the first container has triggered a stop event without having to frequently monitor the first custom resource, thereby saving computer equipment performance.

[0064] In the above embodiments, the computer device will use the operator of the container orchestration system to monitor the working status of the first container. When the monitored working status is stopped, the first persistent task is triggered, and then the first image is generated by executing the first persistent task. That is, the above embodiments realize the generation of the first image through the operator of the container orchestration system. The above embodiments deeply integrate the operator of the container orchestration system, which can automatically save the running status of the first container and the image generation in the life cycle event (such as stop) of the first custom resource, and realize seamless integration with the container orchestration system.

[0065] In one embodiment, in response to the operator of the container orchestration system detecting that the state of the first custom resource is stopped, the monitoring function corresponding to the stopped state is triggered; a first persistent task is created through the monitoring function; and the key parameters required by the first persistent task are sent to the first persistent task through the monitoring function, and the first persistent task is started through the monitoring function.

[0066] like Figure 4 As shown, during the operation of the first container, the operator 401 of the container orchestration system will continuously monitor the status of the first custom resource 402. When the operator 401 detects that the status of the first custom resource 402 is a stopped state, the operator 401 will trigger the monitoring function 403 corresponding to the stopped state. By executing the monitoring function 403, the monitoring function 403 will create the first persistent task 404 and send key parameters to the first persistent task 404 to start the first persistent task 404.

[0067] The monitoring function is a pre-configured function corresponding to the stopped state. That is, when the first container is in a stopped state, the monitoring function will be automatically triggered. This monitoring function is pre-configured by technical personnel. Within the monitoring function, the first persistent task will be created. Optionally, the first persistent task will be created as a Kubernetes Job. The monitoring function will also send the key parameters required by the first persistent task to ensure its successful execution. Afterward, the monitoring function will start the first persistent task. It should be noted that the monitoring function can also include other functions based on the pre-configuration by technical personnel, such as reading the execution result of the first persistent task (success or failure), reading the execution progress of the first persistent task if it fails, restarting the first persistent task, etc.

[0068] In this embodiment, the monitoring function can also be pre-configured by the technician and is not only applicable to starting the first persistent task. The monitoring function can also be integrated with other tasks. For other tasks triggered by the same stop event of the first container, the technician can set up to trigger other tasks through the same monitoring function. In this case, the monitoring function can effectively support the first persistent task and other tasks. By supporting multiple tasks through a unified monitoring function interface, it is convenient to trigger multiple tasks and reduce the amount of code work.

[0069] In one embodiment, when the first container stops running, the first custom resource is updated to a "Stopping" state. In response to the container orchestration system's operator detecting this "Stopping" state, a first persistence task is triggered. Upon completion of the first persistence task, the first custom resource is updated to a "Stopped" state. The "Stopping" state indicates that the task corresponding to the first container's stop event is currently being executed, while the "Stopped" state indicates that the task has been completed. These two distinct identifiers ensure that when the first custom resource is accessed by other components, they are aware of whether the task corresponding to the first container's stop event is currently being executed. Therefore, when executing the first persistence task corresponding to the stop event, other components will not modify the information related to the stopped first container, guaranteeing the successful execution of the first persistence task.

[0070] In the above embodiments, the first custom resource is monitored by the operator of the container orchestration system. When the monitored working state is stopped, the monitoring function is triggered, the first persistent task is created by the monitoring function, and then the first image is generated by executing the first persistent task. The above embodiments make full use of the tools provided by the container orchestration system and achieve deep integration with the container orchestration system.

[0071] Step 360: By executing the first persistence task, the first container that has stopped running is saved as the first image.

[0072] In this embodiment, a computer device saves a first container that has stopped running as a first image by executing a first persistence task. In one embodiment, during the execution of the first persistence task, the computer device saves the first container that has stopped running as a first image by executing a first persistence command. Specifically, during the execution of the first persistence task, the running state of the first container that has stopped running is extracted by executing the first persistence command, and the running state is encapsulated into a first image. Optionally, the running state includes at least one of file system information, environment variable information, runtime configuration information, and node information of the container orchestration system in which it resides.

[0073] In the above embodiments, when the first container stops running, the running state of the first container will be automatically saved, that is, the running state of the first container is persisted, and the first container at this time is a stateful container.

[0074] based on Figure 3 In the optional embodiment shown, a first persistence task is performed in step 360. Illustratively, the execution of the first persistence task includes the following three steps.

[0075] First, obtain key parameters. Optionally, the key parameters are sent to the first persistence task by the monitoring function to ensure the smooth execution of the first persistence task. Optionally, the key parameters include at least one of the following: the node (i.e., worker node) where the process associated with the first container is located, the container runtime environment of the process associated with the first container, the authentication information and address of the first image repository used to store the first image, the name of the first image, and the identifier of the first container.

[0076] The process associated with the first container refers to the process associated with the first container in the container orchestration system. Optionally, if the container orchestration system is Kubernetes, then the process is a Pod. A Pod is the smallest / simplest basic unit created or deployed in a Kubernetes system, and one Pod represents a process running on the Kubernetes system.

[0077] The node where the process associated with the first container resides refers to the node where the process associated with the first container resides in the container orchestration system. The container orchestration system includes multiple nodes. Optionally, if the container orchestration system is Kubernetes, then the process is a Pod, and the node is a node in the Kubernetes cluster.

[0078] The first container's associated process's container runtime environment includes Docker (a container management platform) or Containerd (a container management daemon). Docker is a relatively complete containerization platform that not only includes container operation and management but also provides image management functionality. Containerd, on the other hand, primarily focuses on container operation and management. Kubernetes can use either Docker or Containerd to manage the first container.

[0079] The authentication information and address of the first image repository are used to authenticate the first image repository. When the authentication of the first image repository is successful, the computer device can push the first image to the first image repository. The name of the first image is optional and can be the name of the image stored in the monitoring function pre-configured by the technician. The identifier of the first container is the ID of the first container that has stopped running. The monitoring function sends the identifier of the first container to the first persistence task, so that the first persistence task can establish a mapping relationship between the first image and the first container.

[0080] Second, authenticate the first image repository. Given that the key parameters obtained include the authentication information and address of the first image repository, the first persistence task will authenticate the first image repository based on that information and address. If authentication is successful, it means that the first image repository is allowed to store the first image.

[0081] Third, execute the first persistence command. In one embodiment, by executing the first persistence command, the computer device saves the first container that has stopped running as a first image. In another embodiment, by executing the first persistence command, the computer device pushes the first image to a first image repository. In this application embodiment, the first image is also pushed to the first image repository through a first persistence task, facilitating the use and management of the first image. When the first image is needed, it can be obtained directly from the first image repository, and when the first image needs to be managed, individual management of the first image can be achieved through unified management of multiple images in the first image repository.

[0082] In one embodiment, by executing a first persistence command, the computer device selects the container management client corresponding to the first container as the container management client corresponding to the first image. The container management client, i.e., the container runtime environment mentioned above, includes Docker or Containerd. In this case, the first image inherits the container management client corresponding to the stopped first container, thus ensuring the consistency of the container management client before and after inheritance. If technicians manually generate the first image, in a complex multi-container environment, manual operation is prone to errors, and the container management client corresponding to the first image may not be consistent with the container management client corresponding to the first container. Therefore, the automatic selection of the container management client provided in this application improves the reliability of the container management client corresponding to the first image. Optionally, the computer device executes the corresponding first persistence command based on the container runtime environment (Docker or Containerd) of the process associated with the first container. The format of the executed first persistence command may differ for different container runtime environments.

[0083] In one embodiment, the parameters required by the first persistence command include the container runtime environment of the process associated with the first container, the name of the first image, and the identifier of the first container.

[0084] As an illustration, the first persistence command is shown below:

[0085] commitctl –client $CLIENT commit $CONTAINER_ID $NEWIMAGE_NAME;

[0086] Here, $CLIENT marks the container runtime environment of the process associated with the first container, such as Docker or Containerd; $CONTAINER_ID marks the ID of the first container; and $NEWIMAGE_NAME marks the name of the newly generated first image.

[0087] In one embodiment, image generation is performed through the developer workspace module of the ModelStudio system. Specifically, the user selects to stop the specified workspace on the front-end page of the ModelStudio system. KubernetesOperator detects that the workspace's status is "stopping," at which point KubernetesOperator will enter the stopping process, as shown below.

[0088] 1. When a user selects to stop the workspace on the front end, the workspace's status changes to "stopping".

[0089] 2. When the Workspace Reconciler traverses all workspaces, it finds that one workspace has entered a stopping state and triggers the stopping monitoring function ensureStopped.

[0090] 3. The `ensureStopped` monitoring function starts the persistent task. The persistent task is created as a Kubernetes Job. The `ensureStopped` function passes the following key data to the persistent task: The node on which the pod associated with the workspace to be stopped runs; the container runtime environment (Docker or Containerd) of the pod associated with the workspace to be stopped; the authentication information and address of the registry to be pushed; the name of the new image; and the container ID.

[0091] 4. Ensure the persistence task completes. If it fails, re-enter step 2; if it completes, replace the old image name of the currently stopped workspace and proceed with the subsequent process.

[0092] 5. After the persistence task is completed, ensure that the associated copies in the workspace are deleted.

[0093] 6. Update the workspace status to stopped.

[0094] 7. Process complete.

[0095] The workflow of a persistence task includes: first, obtaining the key parameters of the persistence task; then, authenticating the image repository; and finally, executing the corresponding container persistence command based on the container's runtime environment. An illustrative example of a container persistence command is shown below:

[0096] commitctl–client$CLIENTcommit$CONTAINER_ID$NEWIMAGE_NAME

[0097] `commitctl` is a command-line tool implemented in Go, used to save containers as new images and push them to a specified image repository. `commitctl` uses the `--client` option to select the container management client, and all required parameters are passed through the `ensureStopped` monitoring function. Required parameters include:

[0098] $CLIENT: Specifies the container management client to use, such as docker or nerdctl;

[0099] $CONTAINER_ID: The ID of the container to be saved;

[0100] $NEWIMAGE_NAME: The name of the new image.

[0101] Figure 5 A structural block diagram of an image generation apparatus provided in an exemplary embodiment of this application is shown. The apparatus includes the following modules.

[0102] The monitoring module 501 is used to monitor the working status of the first container during its operation.

[0103] Trigger module 502 is used to trigger the first persistent task in response to detecting that the first container has stopped running;

[0104] The generation module 503 is used to save the first container that has stopped running as the first image by performing a first persistence task.

[0105] In an optional embodiment, the triggering module 502 is further configured to trigger the first persistent task in response to the operator of the container orchestration system detecting that the state of the first custom resource is a stopped state;

[0106] Among them, the first custom resource is the custom resource corresponding to the first container.

[0107] In an optional embodiment, the triggering module 502 is further configured to trigger the monitoring function corresponding to the stop state in response to the operator of the container orchestration system detecting that the state of the first custom resource is a stop state;

[0108] The first persistent task is created using the monitoring function;

[0109] Additionally, the first persistent task is started by sending the key parameters required by the first persistent task to the first persistent task through the monitoring function.

[0110] In an optional embodiment, the generation module 503 is further configured to extract the running state of the first container that has stopped running by performing a first persistence task, and encapsulate the running state into a first image. The running state includes at least one of file system information, environment variable information, runtime configuration information, and node information of the container orchestration system in which it is located.

[0111] In an optional embodiment, the device further includes a push module 504. The push module 504 is used to authenticate the first image repository during the execution of the first persistence task.

[0112] Push the first image to the first image repository.

[0113] In an optional embodiment, the apparatus further includes a selection module 505. The selection module 505 is configured to select, during the execution of the first persistence task, the container management client of the first container as the container management client corresponding to the first image.

[0114] In an optional embodiment, the generation module 503 is further configured to, during the execution of the first persistence task, save the first container that has stopped running as a first image by executing a first persistence command;

[0115] The push module 504 is also used to push the first image to the first image repository by executing the first persistence command during the execution of the first persistence task;

[0116] The selection module 505 is also used to select the container management client of the first container as the container management client corresponding to the first image by executing the first persistence command during the execution of the first persistence task.

[0117] In an optional embodiment, the apparatus further includes an acquisition module 506. The acquisition module 506 is configured to acquire key parameters during the execution of the first persistence task.

[0118] The key parameters include at least one of the following: the node where the process associated with the first container is located, the container runtime environment of the process associated with the first container, the authentication information and address of the first image repository used to store the first image, the name of the first image, and the identifier of the first container:

[0119] In an optional embodiment, the apparatus further includes a setting module 507. The setting module 507 is configured to set the first image as an updated version of the second image, and to set the first image as the default image to be used the next time the first container starts; or, to replace the second image with the first image; wherein the second image is the image used before the first container stopped running.

[0120] In an optional embodiment, the triggering module 502 is further configured to trigger a first persistent task in response to a controller in the operator of the container orchestration system detecting that the state of the first custom resource is a stopped state.

[0121] In summary, in this embodiment, when the first container is detected to have stopped running, a first persistence task is triggered. By executing the first persistence task, the stopped first container is automatically saved as a first image. That is, this embodiment provides a method for automatically generating images, avoiding the tedious manual image building process for technicians. Furthermore, this embodiment deeply integrates the generation of the first image with the lifecycle events of the first container (specifically, the stop event), ensuring that after the first container stops running, the stopped first container can be saved promptly, and the generation and updating of the first image can be performed in a timely manner.

[0122] Figure 6 This illustration shows a structural block diagram of a computer device 600 provided in an exemplary embodiment of this application. The computer device 600 may be a portable mobile terminal, such as a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. The computer device 600 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.

[0123] Typically, computer device 600 includes a processor 601 and a memory 602.

[0124] Processor 601 may include one or more processing cores, such as a quad-core processor, a hexa-core processor, etc. Processor 601 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 601 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 601 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 601 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0125] The memory 602 may include one or more computer-readable storage media, which may be non-transitory. The memory 602 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 602 are used to store at least one instruction, which is executed by the processor 601 to implement the image generation method provided in the embodiments of this application.

[0126] The computer device 600 may also optionally include a peripheral device interface 603 and at least one peripheral device. The processor 601, memory 602, and peripheral device interface 603 can be connected via a bus or signal lines. Each peripheral device can be connected to the peripheral device interface 603 via a bus, signal lines, or a circuit board. The peripheral device interface 603 can be used to connect at least one I / O (Input / Output) related peripheral device to the processor 601 and memory 602. In some embodiments, the processor 601, memory 602, and peripheral device interface 603 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 601, memory 602, and peripheral device interface 603 can be implemented on separate chips or circuit boards, and this embodiment is not limited in this regard.

[0127] Those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the computer device 600, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0128] This application also provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the image generation method provided in the above method embodiments.

[0129] This application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the image generation method provided in the above-described method embodiments.

[0130] The sequence numbers of the embodiments in this application are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware, or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk. The above descriptions are merely optional embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for generating an image, characterized in that, The method includes: During the operation of the first container, the working status of the first container is monitored. When the first container stops running, the first custom resource is updated to the stopped state. In response to the controller in the container orchestration system detecting that the state of the first custom resource is in a stopped state, the monitoring function corresponding to the stopped state is triggered; a first persistent task is created through the monitoring function; and the first persistent task is started by sending the key parameters required by the first persistent task to the first persistent task through the monitoring function, wherein the first custom resource is a custom resource corresponding to the first container; the key parameters include at least one of the following: the node where the process associated with the first container is located, the container runtime environment of the process associated with the first container, the authentication information and address of the first image repository used to store the first image, the name of the first image, and the identifier of the first container; During the execution of the first persistence task, the running state of the first container that has stopped running is extracted by executing the first persistence command, the running state is encapsulated into the first image, the first image is pushed to the first image repository, and the container management client of the first container is selected as the container management client corresponding to the first image; in response to the completion of the first persistence task, the first custom resource is updated to a stopped state; the stopped state is used to prevent other components from changing the relevant information of the first container during the execution of the first persistence task.

2. The method according to claim 1, characterized in that, The running status includes at least one of the following: file system information, environment variable information, runtime configuration information, and node information of the container orchestration system.

3. The method according to claim 1 or 2, characterized in that, The method further includes: During the execution of the first persistence task, the key parameters are obtained.

4. The method according to claim 1 or 2, characterized in that, The method further includes: Use the first image as an updated version of the second image, and set the first image as the default image to be used the next time the first container is started; or, Replace the second image with the first image; The second image is the image used before the first container stopped running.

5. A mirror generation device, characterized in that, The device includes: The monitoring module is used to monitor the working status of the first container during its operation. When the first container stops running, the first custom resource is updated to the stopped state. A triggering module is configured to respond to a controller in the container orchestration system detecting that the state of the first custom resource is in a stopped state, triggering a monitoring function corresponding to the stopped state; creating a first persistent task through the monitoring function; and sending key parameters required by the first persistent task to the first persistent task through the monitoring function to start the first persistent task, wherein the first custom resource is a custom resource corresponding to the first container; the key parameters include at least one of the following: the node where the process associated with the first container is located, the container runtime environment of the process associated with the first container, the authentication information and address of the first image repository used to store the first image, the name of the first image, and the identifier of the first container; The generation module is configured to, during the execution of the first persistence task, extract the running state of the first container that has stopped running by executing a first persistence command, encapsulate the running state into the first image, push the first image to the first image repository, and select the container management client of the first container as the container management client corresponding to the first image; in response to the completion of the first persistence task, the first custom resource is updated to a stopped state; the stopped state is used to prevent other components from changing the relevant information of the first container during the execution of the first persistence task.

6. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the image generation method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is loaded and executed by a processor to implement the image generation method as described in any one of claims 1 to 4.

8. A computer program product, characterized in that, The computer program product stores a computer program that is loaded and executed by a processor to implement the image generation method as described in any one of claims 1 to 4.