A container image cleaning method, electronic equipment and storage medium

By calculating the service value and thermal decay parameters of container images, the importance of images is dynamically assessed, and redundant images are automatically cleaned up by setting target scoring thresholds. This solves the problem of insufficient applicability of container image cleanup strategies and achieves safe and efficient image management.

CN120872508BActive Publication Date: 2025-12-16INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511405718.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-29
Publication Date
2025-12-16
Estimated Expiration
2045-09-29

AI Technical Summary

Technical Problem

In existing technologies, container image cleanup strategies cannot accurately identify whether temporarily unused images will still be used in the production environment, leading to the risk of accidentally deleting critical service images and posing a potential service interruption hazard.

Method used

By calculating the number of services associated with a container image and the service creation time, service value parameters are determined. Combined with the shortest idle time, thermal decay parameters are calculated to dynamically evaluate the service dependency value and usage status of the image. Target scoring thresholds are set to automatically clean up redundant images.

Benefits of technology

It enables precise cleanup of container images, reduces storage usage, avoids accidental deletion of critical images, and improves the applicability and security of the cleanup strategy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872508B_ABST
    Figure CN120872508B_ABST
Patent Text Reader

Abstract

The application discloses a container image cleaning method, an electronic device and a storage medium, relates to the technical field of computers, and comprises the following steps: determining a service value parameter of a target container image according to the number of services running based on the target container image and the creation time of each service; calculating a heat attenuation parameter of the target container image according to the shortest idle time length of each service corresponding to the target container image; calculating a target score of the target container image based on the service value parameter and the heat attenuation parameter; and cleaning the target container image if the target score of the target container image is less than a preset cleaning threshold. The application can effectively identify and clean redundant images, reduce storage occupation, provide protection for long-term low-activity but key container images, avoid mistaken cleaning, and improve the applicability of a container cleaning strategy.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a container image cleaning method, an electronic device and a storage medium. BACKGROUND

[0002] With the rapid development of cloud computing, container technology has become a core technology cornerstone of modern software development. Containers are usually based on static encapsulated container images for running, and a container image is a standardized software packaging format containing all components required for software running, such as application programs, dependent libraries and configuration files. A same container image can create multiple container entities, and multiple software services can be created based on the container entities.

[0003] Due to the expansion of business scale, the number and storage occupation of container images increase exponentially, and the traditional container image cleaning method usually automatically recycles expired container images in combination with the usage time of the container images, for example, deleting a container image that has not been used for more than N days. However, this way cannot distinguish whether a temporarily unused container image will still be used by a production environment, and there is a risk of service interruption due to the mistaken deletion of a container image of a key service. SUMMARY

[0004] The present application provides a container image cleaning method to at least solve the problem of low applicability of container image cleaning strategies in the related art.

[0005] In a first aspect, the present application provides a container image cleaning method, comprising: determining a service value parameter of a target container image according to the number of services based on the target container image and the creation time of each service; wherein the service value parameter is positively correlated with the number of services, and the farther the current time is from the creation time of the service, the slower the service value parameter grows; calculating a heat decay parameter of the target container image according to the shortest idle time length of each service corresponding to the target container image; the shortest idle time length refers to the time difference between the current time and the latest historical access time of each service; the idle time length is positively correlated with the heat decay parameter; calculating a target score of the target container image based on the service value parameter and the heat decay parameter; and cleaning the target container image if the target score of the target container image is less than a preset cleaning threshold.

[0006] In a second aspect, the present application further provides an electronic device, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of any of the above container image cleaning methods.

[0007] In a third aspect, the present application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of any of the container image cleaning methods.

[0008] In a fourth aspect, the present application also provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the steps of any of the container image cleaning methods.

[0009] According to the service value parameter calculated according to the number of services associated with the container image and the service creation time, the service dependency relationship of the container image can be accurately evaluated, and the service dependency value of the container image can be dynamically quantified. The heat decay parameter is calculated by the idle time length of the service, the actual use state of the container image is reflected, the business fluctuation is automatically adapted, finally the redundant image is effectively identified and cleaned according to the target score, the storage occupation is reduced, at the same time, the long-term low-active but key container image can be protected to avoid mis-cleaning, and the applicability of the container cleaning strategy is improved. BRIEF DESCRIPTION OF DRAWINGS

[0010] In order to more clearly illustrate the embodiments of the present application, the drawings needed in the embodiments will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0011] Figure 1 A container image cleaning method application environment diagram is provided for the embodiments of the present application.

[0012] Figure 2 A flowchart of a container image cleaning method is provided for the embodiments of the present application.

[0013] Figure 3 A flowchart of calculating a service value parameter is provided for some embodiments.

[0014] Figure 4 A flowchart of updating a service value parameter is provided for some embodiments.

[0015] Figure 5 A flowchart of calculating a value sacrifice parameter is provided for some embodiments.

[0016] Figure 6 A flowchart of calculating a target score is provided for some embodiments.

[0017] Figure 7 An internal structure diagram of a computer device is provided for some embodiments. DETAILED DESCRIPTION

[0018] The technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0019] It should be noted that in the description of the present application, the terms “comprise”, “contain” or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment comprising a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or equipment. The terms “first”, “second” and the like in the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence.

[0020] In order for those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the drawings and specific embodiments.

[0021] In a first aspect, the embodiments of the present application provide a container image cleaning method. The method can be applied in an application environment as shown in Figure 1 The processor 110 can communicate with the memory 120 through a network to clean the container image in the memory 120. The processor 110 can be implemented by an independent processor or a processor system composed of multiple processors, and the memory 120 can be, but is not limited to, a static random access memory (SRAM), a magnetoresistive random access memory (MRAM) and the like.

[0022] The processor 110 can be implemented in at least one of the following hardware forms: programmable logic array (PLA), field programmable gate array (FPGA), digital signal processor (DSP), application specific integrated circuit (ASIC), general purpose processor or other programmable logic device.

[0023] Of course, the container image cleaning method provided by the embodiments of the present application can also be applied to more unillustrated scenarios.

[0024] The container image cleaning method is applied to the processor 110 in Figure 1 For example, as shown in Figure 2 The container image cleaning method includes steps S210 to S240 that can be executed by the processor 110. Each step will be described below.

[0025] Step S210: determining a service value parameter of the target container image according to the number of services based on the target container image and the creation time of each service.

[0026] The service value parameter is positively correlated with the number of services, and the farther the current time is from the creation time of the service, the slower the service value parameter grows.

[0027] The image warehouse is a system for storing, managing and distributing container images. Container images in the image warehouse can be pulled into a container orchestration system, such as a Kubernetes cluster, and container entities can be built on the nodes of the cluster to provide services based on the code encapsulated by the container image. Based on a container image, multiple services can be created. The more services corresponding to a container image, the more important the container image can be considered to be. Because of the fast pace of technological iteration, the longer the service is created, the lower the probability of service access, and the lower the importance of the corresponding container image.

[0028] In some specific embodiments, the service value parameter of the target container image is calculated according to the number of services corresponding to the target container image and the creation time of each service, which can quantify the importance of the target container image. The larger the service value parameter, the higher the importance of the target container image. As the number of services increases, the service value parameter gradually increases, and the longer the creation time of the service, the slower the growth rate of the service value parameter.

[0029] Step S220: calculating a heat decay parameter of the target container image according to the shortest idle time length of each service corresponding to the target container image.

[0030] The shortest idle time length refers to the time difference between the current time and the latest historical access time of each service. The idle time length is positively correlated with the heat decay parameter.

[0031] Since each service is based on a corresponding container image, when a user accesses a service, it can be determined that the corresponding container image is being used. Similarly, if all services corresponding to the container image have not been accessed, i.e., the service is in an idle state, it can be considered that the corresponding container image is not being used. It can be understood that the importance of a container image that has not been used for a long time should be reduced.

[0032] Heat can be used to reflect the frequency of use of a container image. The higher the heat value, the higher the frequency of use. The heat decay parameter can measure the degree of reduction in the frequency of use of the container image.

[0033] In some specific embodiments, by retrieving the access status of each service corresponding to the target container image, the time of the most recent historical access of each service can be determined, that is, the time when the target container image was last used. The time difference between the current time and the most recent historical access time is used as the shortest idle time, which can characterize the idle time of the target container image. Then, the thermal decay parameter of the target container image is calculated by the idle time, and the importance of the target container image is dynamically updated. The longer the idle time, the greater the thermal decay parameter.

[0034] Step S230: Calculate the target score of the target container image based on the service value parameter and the thermal decay parameter.

[0035] Specifically, the importance of the target container image is quantified by the service value parameter, and the importance of the target container image is updated by the thermal decay parameter to obtain the final target score, which reflects the current importance of the target container image.

[0036] Step S240: If the target score of the target container image is less than the preset cleanup threshold, then clean up the target container image.

[0037] Specifically, the rating of each container image is obtained periodically. If the target rating of the target container image is less than the cleanup threshold (0.8), the target container image is deleted from the image repository.

[0038] In some optional embodiments, the cleanup threshold setting can be dynamically adjusted according to the strictness and leniency of the cleanup strategy. When the cleanup threshold is large, it can be applied to scenarios where high-frequency services are created, allowing for timely cleanup of container images to adapt to the service iteration rate. When the cleanup threshold is small, it can be applied to scenarios where long-tail services are protected, ensuring the security of most container images. This application does not impose any limitations on this.

[0039] The container image cleanup method described above calculates service value parameters by using the number of services associated with the container image and the service creation time. This allows for accurate assessment of the service dependencies of the container image and dynamic quantification of its service dependency value. It also calculates thermal decay parameters by using the idle time of services to reflect the actual usage status of the container image, automatically adapting to business fluctuations. Finally, it effectively identifies and cleans up redundant images based on target scores, reducing storage consumption. Furthermore, it protects long-term inactive but critical container images, preventing accidental cleanup and improving the applicability of the container cleanup strategy.

[0040] In some embodiments, such as Figure 3 As shown, when the processor 110 executes step S210, it may also include at least steps S211 to S213.

[0041] Step S211: determining the initial value contribution parameter of each service according to the creation order of each service.

[0042] The later the service is created, the lower the initial value contribution parameter corresponding to the service is.

[0043] The value contribution parameter is used to represent the magnitude of the importance of the container image that the service promotes. The greater the value contribution parameter of the service, the greater the magnitude of the importance of the container image that the service promotes. The value contribution parameter is obtained according to the initial value contribution parameter corresponding to the service and the value contribution decay rate.

[0044] In some specific embodiments, the service value parameter of the target container image increases every time a service running on the target container image is created, and the contribution of each service to the service value parameter is different due to the different creation orders, that is, the initial value contribution parameters of different services are different.

[0045] For example, for a target container image, when a service 1 running on the target container image is created for the first time, the initial value contribution parameter corresponding to the service 1 is 6, when a service 2 is created for the second time, the initial value contribution parameter corresponding to the service 2 is 5, when a service 3 is created for the third time, the initial value contribution parameter corresponding to the service 3 is 4, and so on, gradually decreasing until the initial value contribution parameter decreases to 1, and the initial value contribution parameter of the subsequent service remains 1, that is, the initial value contribution parameters of each service corresponding to the target container image are A i = 6-i (A i The minimum is 1, where i is the creation order of the service.

[0046] When a service running on the target container image is created each time, additional personalized code is usually added to the target container image to realize the functional difference between different services, and when the number of services increases, the expandable functions are usually less, that is, the implementability of adding personalized code to the target container image is smaller, therefore, the initial value contribution parameter of the service created later is lower than that of the service created earlier, so the initial value contribution parameters of different services gradually decrease according to the creation order. However, in order to ensure that the service value parameter of the target container image increases with each newly added service, the initial value contribution parameter of the service is set to be at least 1.

[0047] In some optional embodiments, the initial value contribution parameters of different services can also be the same, for example, the initial value contribution parameter of each service is set to 1, that is, the service value parameter of the target container image increases by 1 each time a service is created, which is not limited in the present application.

[0048] Step S212: Based on the difference between the current time and the creation time of each service, and the preset value decay coefficient, the value contribution decay rate of each service is determined respectively.

[0049] Due to the faster technical iteration, the service update speed is also faster, and the probability of being accessed by the service created earlier is lower, that is, the value contribution after the service is created will decay with the passage of time, therefore, based on the creation time of the service, the value contribution decay rate can be calculated to reflect the technical iteration rate.

[0050] Exemplarily, t i is the creation time corresponding to the i-th created service, t is the current time, and the value contribution decay rate of the service is e^(-α(t-t i )), wherein ∂ is a preset value decay coefficient for controlling the decay speed of the initial value contribution parameter, and the value of ∂ is fitted according to the service usage in actual application, and is usually 0.01±0.002. The value of t-t i is in units of "days".

[0051] Step S213: Based on the initial value contribution parameter and the value contribution decay rate corresponding to each service respectively, the value contribution parameter of each service is determined, and based on the sum of the value contribution parameters of each service, the service value parameter of the target container image is determined.

[0052] Specifically, the product A i ×e^(-α(t-t i )) of the initial value contribution parameter and the value contribution decay rate can be used as the value contribution parameter corresponding to each service, and the service value parameter of the target container image is the sum of the value contribution parameters of each service, that is, , wherein V(t) is the service value parameter of the target container image. When α=0.01, every day after the service is created, , the value contribution parameter of each service is A i ×0.99, that is, the final value contribution parameter of each service is 99% of the initial value contribution parameter, which means that the initial value contribution parameter decays about 1% per day.

[0053] By quantifying the importance of the target container image through the dependency relationship between the target container image and the service, and using the value contribution decay parameter to control the growth amplitude of the service value parameter, the variation amplitude of the service value parameter is more consistent with the actual working condition, and the intelligence of the container image management is improved.

[0054] In some embodiments, step S220 can include step S221: determining the heat decay parameter of the target container image according to a buffer difference between the shortest idle duration and a preset decay start time control factor, and a preset decay upper limit control coefficient and a decay rate control coefficient.

[0055] wherein the buffer difference is negatively correlated with the heat decay parameter.

[0056] Specifically, the heat decay parameter of the target container image is related to the access frequency of the service, and during a period of time after the service is just created, the service is in the startup phase and usually has no access record. Therefore, in order to ensure that the heat of the target container image remains stable in the short term after the service is created to adapt to the cold start period of the service and avoid triggering decay too early, the decay start time control factor can be used to control the decay start time, and the decay upper limit control coefficient and the decay rate control coefficient can be used to control the upper limit and the decay rate of the heat decay, respectively.

[0057] For example, the heat decay function is set as λ(T) = β / (1+e^(-γ(T-(N+δ)))), wherein λ(T) is the heat decay parameter, β is the decay upper limit control coefficient (with a value of 0.2 to 0.3), γ is the decay rate control coefficient (with a value of 0.15 to 0.25), T is the shortest idle duration (in “days”), N is the default decay start time (with a value of 30), and δ is the smoothing offset (with a value of 5 to 10). N and δ together constitute the decay start time control factor, and the unit used is “days”.

[0058] The value of β determines the upper limit of the decay of the heat value of the target container image. When the shortest idle duration T tends to infinity, the value of T-(N+δ) is positive, the value of 1+e^(-γ(T-(N+δ))) tends to 1, and λ(T) tends to β (0.2 to 0.3), indicating that the heat value of the target container image eventually stabilizes at 20% to 30% of the initial value, which is consistent with the usage state of long-term low-active container images in actual applications.

[0059] The value of γ determines the decay rate of the heat value of the target container image. The greater γ is, the faster the decay rate is.

[0060] The value of N+δ determines the time when the heat value of the target container image starts to decay. Only when the value of T-(N+δ) is greater than 0, the value of λ(T) will be greater than 0 (rather than tending to 0), indicating that the heat value of the target container image starts to decay.

[0061] According to the above heat decay function, the greater the shortest idle duration T is, the greater the value of λ(T) is, and the more the heat value of the target container image decays.

[0062] In some cases, for the container image in the decay start time, that is, T-(N+δ) is less than 0, the value of 1+e^(-γ(T-(N+δ))) tends to infinity, and the thermal decay parameter λ(T) of the container image tends to 0, at this time, the thermal value of the container image will not decay. Therefore, within the N+δ corresponding to the number of days, it can be considered that the container image is in the thermal value protection period, wherein N is the default protection period set for all container images, and different smoothing offsets δ can be set according to the particularity of different container images to adaptively extend the protection period.

[0063] In some optional embodiments, the values of β, γ, N, and δ can be fitted according to the thermal value of the container image (that is, the frequency of use of the container image) in actual application, and the present application only serves as an example, which is not limited.

[0064] In some embodiments, the processor 110 can further perform step S221-A before performing step S221: determining the decay speed control coefficient according to the target release range of the target container image.

[0065] Wherein, the larger the target release range is, the larger the decay speed control coefficient is.

[0066] Specifically, when the container image is released to the image warehouse, the release range thereof can be set, for example, a private container image limited to use within a specific organization, and the release range thereof is a user with specific organization authority; a global container image available to all users, and the release range thereof is all users.

[0067] Generally, the frequency of use of a private container image is lower than that of a global container image, and therefore, the thermal value of the private container image should decay faster, that is, different decay speed control coefficients can be set for container images with different release ranges, so that the thermal value of the container image with a smaller release range decays faster, and the thermal value of the container image with a larger release range decays slower.

[0068] In some optional embodiments, different decay upper limit control coefficients, default decay start times, and smoothing offsets can also be set for the release range of the container image or other associated factors of the container image, which are not limited by the present application.

[0069] By judging the use of the container image through the thermal decay parameter, in the case where the idle duration is always less than the decay start time control factor, the thermal value almost does not decay, and the service value parameter of the target container image will always be greater than the cleaning threshold, ensuring that the frequently used target container image will not be cleaned.

[0070] In some embodiments, as Figure 4As shown, the cleaning method of the container image further includes steps S410 to S420 executable by the processor 110.

[0071] Step S410: If at least one target service in each service is deleted, determine a service value sacrifice parameter according to the number of services and the creation time of the target service.

[0072] In some specific embodiments, when at least one target service corresponding to the target container image is deleted, the service value parameter of the target container image will decrease, and the decrease amplitude depends on the service value sacrifice parameter corresponding to the deleted target service, and the service value sacrifice parameter of the target service is related to the creation time of the target service and the number of services originally corresponding to the target container image.

[0073] Step S420: Update the service value parameter based on the service value sacrifice parameter.

[0074] Specifically, the difference between the service value parameter and the service value sacrifice parameter is taken as the updated service value parameter.

[0075] In some embodiments, as Figure 5 shown, the processor 110 can further include steps S411 to S413 when performing step S410.

[0076] Step S411: Determine an initial value sacrifice parameter of the target service according to the number of services.

[0077] Wherein, the number of services is negatively correlated with the initial value sacrifice parameter of the target service.

[0078] Specifically, the number of services refers to the number of services corresponding to the target container image before the target service is deleted.

[0079] For example, the services corresponding to the target container image include service 1, service 2 and service 3, and according to the content recorded in the foregoing step S211, it can be known that the minimum value of the initial value contribution parameter A i of each service is 3, regardless of whether the deleted target service is service 1, service 2 or service 3, the initial value sacrifice parameter B ii corresponding to the deleted target service is 3, that is, the initial value sacrifice parameter of the target service is 6-ii, wherein ii is the number of services corresponding to the target container image before the target service is deleted, and the more the number of services, the smaller the initial value sacrifice parameter, which corresponds to the value of A i , and the minimum value of B ii is also 1.

[0080] In some optional embodiments, if the initial value contribution parameter of each service is 1, the initial value sacrifice parameter of each target service is also 1, which is not limited in the application.

[0081] Step S412: determining a value sacrifice decay rate of the target service based on a difference between the current time and a creation time of the target service, and a preset value decay coefficient.

[0082] Specifically, corresponding to the content described in the foregoing step S212, the value sacrifice decay rate of the target service is e^(-α(t-t i )), where ∂ is a preset value decay coefficient.

[0083] Step S413: determining a service value sacrifice parameter based on the initial value sacrifice parameter and the value sacrifice decay rate.

[0084] Specifically, the product B ii ×e^(-α(t-t i )) of the initial value sacrifice parameter and the value sacrifice decay rate can be used as the value sacrifice parameter corresponding to the deleted target service.

[0085] The service value parameter is updated based on the service value sacrifice parameter, that is, V’(t)=V(t)-B ii ×e^(-α(t-t i )), where V’(t) is an updated service value parameter.

[0086] The number of services corresponding to the target container image is reduced, which reflects that the importance of the target container image is lower, and the service value parameter of the target container image is updated by the service sacrifice parameter of the deleted target service, which can dynamically quantify the service dependency value of the target container image.

[0087] In some embodiments, as shown in Figure 6 , the container image cleaning method further includes steps S610 to S620 executable by the processor 110.

[0088] Step S610: determining an initial score of the target container image according to a target image attribute corresponding to the target container image.

[0089] Specifically, according to the image attribute, the container image can be at least divided into a base image and a business image, where the base image is a container image that is used by most businesses and has a generally high importance, and the business image is a container image that is used by a small part of special businesses and has a slightly lower importance. Based on this, different initial scores can be set for container images with different attributes, for example, the initial score of the base image is set to 20, and the initial score of the business image is set to 5.

[0090] In some optional embodiments, the container images can also be divided into different images according to the mirror image attribute, and different initial scores of different segments are determined for different images, which is only an example and the present application does not limit this.

[0091] Step S620: According to the initial score of the target container image, the service value parameter and the heat decay parameter, the target score of the target container image is calculated.

[0092] Specifically, the calculation method of the target score can be S(t)=S base +V(t)-∫λ(T)dt, wherein S(t) is the target score, S base is the initial score of the target container image, V(t) is the service value parameter of the target container image, λ(T) is the heat decay parameter of the target container image, and the integral interval of λ(T) is the latest historical access time t last of each service corresponding to the target container image to the current time t now , and ∫λ(T)dt can be understood as the summation of the heat decay parameter corresponding to the target container image every day in the process from the latest historical access time t last to the current time t now , representing the cumulative decay amount.

[0093] By quantifying the importance of the container image through the initial score and the service value parameter, and accurately evaluating the usage state of the container image through the heat decay parameter, the precise cleaning of the container image can be realized, and the false deletion rate can be reduced.

[0094] In some embodiments, the cleaning method of the container image further includes step S710 which can be executed by the processor 110: if the target score of the target container image is greater than a preset protection threshold, the target container image is added to a preset image white list, and the target score is cleared.

[0095] Among them, the container images in the image white list cannot be cleaned.

[0096] Specifically, if the number of services corresponding to the target container image increases continuously, resulting in the continuous growth of the service value parameter of the target container image, and each service corresponding to the target container image is frequently used, resulting in a lower heat value decay, there is a case that the target score of the target container image is greater than the preset protection threshold, at this time, it can be considered that the importance of the target container image meets the protection requirement, and the target container image is added to the image white list, which can ensure that the target container image is never deleted. At the same time, the calculation of the target score is not performed for the container images in the image white list, which can reduce a certain amount of computing power consumption.

[0097] The preset protection threshold value can be set and dynamically adjusted according to actual conditions, and the present application does not limit this.

[0098] In some optional embodiments, for some important container images that developers consider cannot be deleted, they can be directly recorded in the image whitelist, so that they are not processed objects of the container image cleaning method described in the foregoing, thereby ensuring the security of important container images, and the present application does not limit this.

[0099] In addition, the container images in the image whitelist can be regularly manually screened and cleaned to prevent the image whitelist from overflowing.

[0100] In some embodiments, the container image cleaning method further includes step 610 that can be performed by the processor 110: listening to service creation events and service deletion events in the container orchestration platform, and in response to the service creation events and the service deletion events, obtaining scoring association data of a target container image, so as to calculate a target score of the target container image based on the scoring association data.

[0101] The scoring association data of the target container image at least includes the number of services running based on the target container image, the creation time of each service, the shortest idle duration of each service, and other optional data for calculating the target score.

[0102] The container image cleaning method described above can be used to clean the container images in the image repository, or can be used to clean the container image copies saved in the local of the container orchestration system, and the present application does not limit this.

[0103] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases the former is a better embodiment.

[0104] In the second aspect, the embodiments of the present application provide a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the container image cleaning method provided in any embodiment of the first aspect of the present application when executing the computer program.

[0105] In some embodiments, the computer device can be a server, and its internal structure diagram can be as shown in Figure 7As shown in the figure. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium, an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store container image data. The network interface of the computer device is used to communicate with the external terminal through the network connection. The computer program is executed by the processor to implement the cleaning method of the container image in any embodiment of the present application.

[0106] Those skilled in the art can understand that, Figure 7 The structure shown in the figure is only a block diagram of part of the structure related to the embodiment scheme of the present application, and does not constitute a limitation on the computer device to which the embodiment scheme of the present application is applied. The specific computer device can include more or less components than those shown in the figure, or combine certain components, or have a different component arrangement.

[0107] In a third aspect, the embodiments of the present application provide a computer readable storage medium having a computer program stored thereon, and the computer program is executed by the processor to implement the steps of the cleaning method of the container image provided in any embodiment of the first aspect of the present application.

[0108] The computer readable storage medium can be Figure 7 The computer readable storage medium in the computer device shown in the figure.

[0109] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, databases, or other media in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchnonous Link) DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct RAM bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0110] In a fourth aspect, the embodiments of the present application also provide a computer program product, which comprises a computer program. When the computer program is executed by a processor, the steps in any of the above-mentioned container image cleaning method embodiments are implemented.

[0111] The skilled in the art can further realize that the units and algorithm steps of the examples described in connection with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general terms in the above description. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. The skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0112] The above provides a container image cleaning method, an electronic device and a storage medium. The principles and implementation modes of the present application are described by applying specific examples. The above description of the examples is only to help understand the method and its core idea. It should be pointed out that for those skilled in the art, without departing from the principles of the present application, some improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the present application.

Claims

1. A method of cleaning a container mirror image, comprising: The method comprises the following steps: determining a service value parameter of the target container image according to the number of services running based on the target container image and the creation time of each service; wherein the service value parameter is positively correlated with the number of services, and the farther the current time is from the creation time of the service, the slower the service value parameter grows; if at least one target service in the services is deleted, determining an initial value sacrifice parameter of the target service according to the number of services; wherein the number of services is negatively correlated with the initial value sacrifice parameter of the target service; determining a value sacrifice decay rate of the target service based on the difference between the current time and the creation time of the target service and a preset value decay coefficient; determining the service value sacrifice parameter based on the initial value sacrifice parameter and the value sacrifice decay rate; updating the service value parameter based on the service value sacrifice parameter; calculating a heat decay parameter of the target container image according to the shortest idle time length of each service corresponding to the target container image; the shortest idle time length refers to the time difference between the current time and the latest historical access time of the services; the idle time length is positively correlated with the heat decay parameter; calculating a target score of the target container image based on the updated service value parameter and the heat decay parameter; if the target score of the target container image is less than a preset cleaning threshold, cleaning the target container image.

2. The method of claim 1, wherein, The method comprises the following steps: determining an initial value contribution parameter of each service according to the creation order of the services; wherein the later the service is created, the lower the initial value contribution parameter of the service is; determining a value contribution decay rate of each service based on the difference between the current time and the creation time of the service and a preset value decay coefficient; determining a value contribution parameter of each service based on the initial value contribution parameter and the value contribution decay rate corresponding to each service, and determining the service value parameter of the target container image according to the sum of the value contribution parameters of the services.

3. The method of claim 1, wherein, The method comprises the following steps: determining the heat decay parameter of the target container image according to the buffer difference between the shortest idle time length and a preset decay starting time control factor, and a preset decay upper limit control coefficient and decay velocity control coefficient; wherein the buffer difference is negatively correlated with the heat decay parameter.

4. The method of claim 3, wherein, The method further comprises the following steps: determining the decay velocity control coefficient according to the target release range of the target container image before calculating the heat decay parameter of the target container image according to the shortest idle time length of each service corresponding to the target container image; wherein the larger the target release range is, the larger the decay velocity control coefficient is.

5. The method of claim 1, wherein, Corresponding to the container image has a preset image attribute, then the target score of the target container image is calculated based on the service value parameter and the heat attenuation parameter, including: According to the target image attribute corresponding to the target container image, determining the initial score of the target container image; According to the initial score of the target container image, the service value parameter and the heat attenuation parameter, the target score of the target container image is calculated.

6. The method of claim 1, wherein, The method further comprises: Listening to service creation events and service deletion events in the container orchestration platform, and in response to the service creation events and the service deletion events, obtaining the score association data of the target container image, so as to calculate the target score of the target container image based on the score association data.

7. The method of claim 1, wherein, The method further comprises: If the target score of the target container image is greater than a preset protection threshold, the target container image is added to a preset image whitelist, and the target score is cleared.

8. An electronic device, comprising: Including: Memory for storing computer programs; Processor for executing the computer program to realize the steps of the container image cleaning method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Root mirror image service quality monitoring method and device, electronic equipment and storage medium

    CN116781565A

  • Docker mirror image cleaning method and device, electronic equipment and storage medium

    CN117215726A