Virtualized container startup and information maintenance method, electronic device and storage medium
By configuring startup tools and shared storage space in virtualized containers, the startup order and status of containers are managed in a unified manner, solving the problem of complex script dependencies in container startup in existing technologies, and achieving standardization and simplification of container startup.
Patent Information
- Application Number
- CN202010727944.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-23
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2040-07-23
AI Technical Summary
In existing technologies, starting a virtualized container requires a specific script encapsulation for each container, which makes the implementation process complex and unsuitable for business scenarios where multiple containers run simultaneously.
By configuring startup tools in each container, and leveraging the dependency relationships between containers in the shared storage space and the pre-startup callback interface, the startup order and state of containers can be managed uniformly, thus achieving a standardized startup process for containers.
It simplifies the container startup process, standardizes the sequential startup of containers, eliminates the need to encapsulate different scripts for each container, and improves the efficiency and maintainability of container startup.
Smart Images

Figure CN112052067B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of virtualized containers, and in particular to a virtualized container startup and information maintenance method, an electronic device and a storage medium. Background Art
[0002] Currently, there are two ways to start a virtualized container. The first way: In Docker Compose, use scripts and other tools to encapsulate the startup command of the container. However, since the script is not universal, the encapsulation script needs to be rewritten for each container, and the encapsulation process is complicated. The second way is only applicable to the process of initializing the container. During the process of initializing the container, it is necessary to ensure that the previous container is initialized and started and then exited before the next container can be initialized and started. However, in the actual business operation process, multiple containers are usually required to run at the same time, so the second way is not applicable to controlling the startup process of the container during the business operation.
[0003] It can be seen that in the prior art, the startup of the container needs to rely on the script encapsulated in each container. Since the scripts encapsulated in each container are different, the implementation process is complicated. Summary of the invention
[0004] The embodiments of the present invention provide a virtualized container startup and information maintenance method, an electronic device and a storage medium, which are used to solve the problem in the prior art that the startup of the container needs to rely on the script encapsulated for each container, and the scripts encapsulated for each container are different, which makes the implementation process complicated.
[0005] In view of the above technical problems, in a first aspect, an embodiment of the present invention provides a method for starting a virtualized container, comprising:
[0006] The startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, or queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence;
[0007] According to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-startup callback interface, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, send a startup command to any of the containers through the execution callback interface, otherwise, do not send the startup command to any of the containers.
[0008] Optionally, after starting the container to be started, the method further includes:
[0009] After detecting that the startup of any container is completed, a file in a preset format is written to the folder where any container is located in the shared storage space through a notification callback interface, and the file in the preset format is used as a completion startup identifier of the mapping of any container.
[0010] Optionally, querying whether the dependent container identifier is mapped to a startup identifier through the pre-startup callback interface until the dependent container identifier is mapped to a startup identifier, comprises:
[0011] The pre-start callback interface is used to query whether the dependent container identifier is mapped to the start identifier at preset time intervals until the dependent container identifier is mapped to the start identifier.
[0012] Optionally, before the startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, the method further includes:
[0013] The configuration file is generated according to the identifier of the dependent container that any container depends on when starting any container, which is configured when any container is created.
[0014] In a second aspect, an embodiment of the present invention provides a method for maintaining virtualized container information, which is applied to a shared storage space, and includes:
[0015] Obtaining a startup sequence corresponding to any container in the container set configured through an interactive interface when starting each container in the container set, and storing an identifier of any container and the startup sequence corresponding to any container in a dependent container relationship in a shared storage space;
[0016] The startup order corresponding to any one of the containers is determined according to the container on which each container is dependent when each container in the container set is created, configured for starting each container; the shared storage space is shared by the container set to which the any one of the containers belongs; and the container set includes at least two containers having a startup order.
[0017] Optionally, it also includes:
[0018] Receiving a first query request sent by a startup tool configured in any container through a pre-startup callback interface; the first query request is used to request to query an identifier of a dependent container of any container according to an identifier of the any container;
[0019] querying, from the dependent container relationships stored in the shared storage space, the identifier of a container whose startup sequence is adjacent to the startup sequence of any container and which is started before any container, and using the identifier of the queried container as the identifier of the dependent container of any container;
[0020] The identifier of the dependent container of any container is returned to the startup tool through the pre-startup callback interface.
[0021] Optionally, it also includes:
[0022] receiving a second query request sent by a startup tool configured in any container through the pre-startup callback interface, wherein the second query request is used to query whether an identifier of a dependent container of any container is mapped to a startup identifier;
[0023] According to the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, query whether the identifier of the dependent container of any container is mapped to the completion startup identifier; if so, send a query response to the startup tool through the pre-startup callback interface; otherwise, do not send the query response to the startup tool; the query response is used to indicate that the query to the dependent container's identifier is mapped to the completion startup identifier.
[0024] Optionally, it also includes:
[0025] Receiving a write instruction sent by a startup tool configured in any container through a notification callback interface; the write instruction is used to indicate that a startup flag is written to any container;
[0026] A file in a preset format is written into the folder where any one of the containers in the shared storage space is located, and the file in the preset format is used as a completion start identifier of mapping any one of the containers.
[0027] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the virtualized container startup method or the virtualized container information maintenance method described above are implemented.
[0028] In a fourth aspect, an embodiment of the present invention provides a non-transitory readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above-described virtualized container startup methods or virtualized container information maintenance methods.
[0029] The embodiments of the present invention provide a virtualized container startup and information maintenance method, an electronic device, and a storage medium, wherein a startup tool is configured for each container. After the startup tool obtains the identifier of the dependent container of any container in which it is located, or after the identifier of the dependent container of any container is queried from the dependent container relationship stored in the shared storage space through the pre-startup callback interface, if the identifier of the dependent container is queried from the shared storage space through the pre-startup callback interface to complete the startup identifier, the any container is started by executing the callback interface. Through the shared storage space shared by the container set to which any container belongs, the startup tool can query the dependent container, query the startup status of the dependent container, and write the startup status of the container through a unified interface, thereby eliminating the need to encapsulate different scripts for the container, achieving standardization of the container startup process, and simplifying the implementation process of sequential startup of the container. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Figure 1 It is a flowchart of a method for starting a virtualized container provided by an embodiment of the present invention;
[0032] Figure 2 It is a schematic diagram of the principle of controlling the start of a container by a start tool provided by another embodiment of the present invention;
[0033] Figure 3 is a flowchart of a method for maintaining virtualized container information provided by another embodiment of the present invention;
[0034] Figure 4 is a schematic diagram of an implementation flow of orderly starting a container provided by another embodiment of the present invention;
[0035] Figure 5 is a structural block diagram of a virtualized container startup device provided by another embodiment of the present invention;
[0036] Figure 6 is a structural block diagram of a virtualized container information maintenance device provided by another embodiment of the present invention;
[0037] Figure 7 It is a schematic diagram of the physical structure of an electronic device provided by another embodiment of the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] In some scenarios, it is necessary to control the startup sequence of virtualized containers. To this end, the present application provides a virtualized container startup method, which is executed by any startup tool that manages the startup of virtualized containers. Among them, each container is configured with a startup tool for controlling the startup of the container.
[0040] The virtualized container startup method provided in this application can be applied to at least one of the following application scenarios:
[0041] Scenario 1: The startup of a container depends on the services provided by the previous container. For example, if the services provided by the previous container are Web Server and / or database, the Web Server must wait until the database is started and available before it can be started.
[0042] Scenario 2: The container needs to complete initialization configuration for the next container or service. For example, it is necessary to collect necessary cluster information, node information, network service information, etc. for the next container and pre-set them in the configuration file, or download the required configuration file or data file from the remote Git repository or file system.
[0043] Scenario 3: The container needs to send the self-registration information of the Pod or service to the remote service. Only after the registration is completed can other containers in the Pod or service be started.
[0044] Figure 1 For a flow chart of the virtualized container startup method provided in this embodiment, see Figure 1 The virtualized container startup method includes the following steps:
[0045] Step 101: a startup tool configured in any container obtains an identifier of a dependent container of any container from a configuration file of any container, or queries the identifier of the dependent container of any container from a dependent container relationship stored in a shared storage space through a pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by a container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of containers in the container set and the corresponding startup sequence;
[0046] Step 102: According to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-start callback interface, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, send a startup command to any of the containers by executing the callback interface, otherwise, do not send the startup command to any of the containers.
[0047] Figure 2 See the schematic diagram of the principle of controlling the startup of the container provided by the startup tool of this embodiment. Figure 2 Each container in the container set is configured with a startup tool, and the startup tool cyclically executes the above steps 101 and 102 to start the container in which it is located. The dependent container of any container refers to the container that must have been started when any container is started.
[0048] For the startup tool configured in any container, first determine the identifier of the dependent container of any container in step 101. There are two ways to obtain it:
[0049] Method 1: Obtain from the configuration file of any container. The configuration file includes the identifier of the container whose startup order is configured before the container when the container is created and whose startup order is adjacent to the container (i.e., the dependent container of the container). The startup tool configured in the container obtains the identifier of the dependent container of the container from the configuration file of the container through the get command.
[0050] Approach 2: The startup tool queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface provided to the outside world, based on the identifier of any container in which it is located (the identifier of any container can be written into the startup tool when the startup tool is configured in any container).
[0051] For the above-mentioned approach 2, specifically, the startup tool sends the identifier of any container and the first query instruction to the shared storage space through the pre-start callback interface, so that the shared storage space queries the identifier of the dependent container of any container from the stored dependent container relationship according to the identifier of any container, and returns the identifier of the dependent container of any container to the startup tool through the pre-start callback interface. The first query request is used to request to query the identifier of the dependent container of any container according to the identifier of the any container.
[0052] After determining the identifier of the dependent container of any container, it is queried in step 102 whether the dependent container of any container has been started. If so, a start command is sent to any container by executing the callback interface to start any container. Otherwise, no start command is sent to any container, so that any container is in a state of waiting to be started.
[0053] It should be noted that any container in the container set that has completed startup has a mapping relationship between the identifier of the container that has completed startup and the startup completion identifier stored in the shared storage space. Therefore, each startup tool can query from the shared storage space whether the dependent container of any container has completed startup through the mapping relationship.
[0054] Specifically, in the above step 102, the startup tool sends the identifier of the dependent container of any container and the second query request to the shared storage space through the pre-startup callback interface, so that the shared storage space queries whether the dependent container of any container has mapped the startup identifier according to the identifier of the dependent container of any container. If so, it means that the startup of the dependent container of any container has been completed, otherwise, the startup of the dependent container of any container has not been completed. The second query request is used to request whether the identifier of the dependent container of any container has mapped the startup identifier.
[0055] In this embodiment, a startup tool is configured for each container. The startup tool queries the dependent containers of the container and the startup status of the dependent containers through the shared storage space through the pre-startup callback interface, and sends a startup command to the container where it is located through the execution callback interface to complete the startup of the container. The startup tool can query the relevant information of the dependent container from the shared storage space through a unified pre-startup callback interface, and after the container is started, write a notification callback interface that writes the startup completion mark, and complete the startup control by interacting with the container through the execution callback interface. It can be seen that the startup of the container is realized in a unified process through the interaction between the startup tool and the shared storage volume, and the interaction between the startup tool and the container where it is located. This embodiment standardizes the process of container startup. Compared with the prior art, there is no need to encapsulate different scripts for different containers, but only by the startup tool installed in the container, the container startup can be realized through the interaction between the startup tool and the shared storage space. The standardization of the container startup process is conducive to simplifying the implementation process of sequential startup of containers.
[0056] This embodiment provides a method for starting a virtualized container, and a startup tool is configured for each container. After the startup tool obtains the identifier of the dependent container of any container in which it is located, or after the startup tool queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface, if the identifier mapping of the dependent container is queried from the shared storage space through the pre-startup callback interface to complete the startup identifier, then the any container is started by executing the callback interface. Through the shared storage space shared by the container set to which any container belongs, the startup tool can query the dependent container, query the startup status of the dependent container, and write the startup status of the container through a unified interface, so that there is no need to encapsulate different scripts for the container, which realizes the standardization of the container startup process and simplifies the implementation process of sequential startup of containers.
[0057] Furthermore, based on the above embodiment, it also includes:
[0058] After detecting that the startup of any container is completed, a file in a preset format is written to the folder where any container is located in the shared storage space through a notification callback interface, and the file in the preset format is used as a completion startup identifier of the mapping of any container.
[0059] The startup tool configured in any container can determine whether the startup of any container is completed by changing parameters before and after the startup of the container is completed.
[0060] After detecting that the startup of any container is completed, the startup tool calls the notification callback interface to write a completion startup identifier mapped to the identifier of any container in the shared storage volume. It should be noted that, in this embodiment, the startup completion identifier refers to a file in a preset format. For example, the file in the preset format is finish.ok. For example, after the startup of the container named "Container Name 1" is completed, the startup tool configured in the container stores the finish.ok file under the file where the container is located in the shared storage space through the notification callback interface, so that the file directory where the stored finish.ok file is located contains the following file: " / Service Name 1 / Container Name 1 / finish.ok".
[0061] Specifically, after detecting that any container has been started, the startup tool sends a write instruction to the shared storage space through the notification callback interface, so as to store a file in a preset format in a folder of the container in the shared storage space according to the write instruction, and use the file in the preset format as a startup completion mark of the container. The write instruction includes the mark of the container.
[0062] In this embodiment, after the container is started, the startup tool of the container stores a file in a preset format in the folder of the container in the shared storage space through the notification callback interface, and uses the file in the preset format as a startup completion mark. A simple method for writing a startup completion mark is provided, which realizes the marking of the container after the startup is completed, and provides a basis for judging whether the container is started.
[0063] Further, based on the above embodiments, querying whether the dependent container identifier is mapped to the startup identifier through the pre-startup callback interface until the dependent container identifier is mapped to the startup identifier, includes:
[0064] The pre-start callback interface is used to query whether the dependent container identifier is mapped to the start identifier at preset time intervals until the dependent container identifier is mapped to the start identifier.
[0065] When the startup tool queries whether the mapping of the dependent container's identifier to the startup identifier of any container is completed, if the mapping of the dependent container's identifier to the startup identifier is not completed for the first query, the startup tool continues to repeat the query process at a preset time interval until the mapping of the dependent container's identifier to the startup identifier is completed. The preset time interval can be preset, for example, 5 seconds.
[0066] This embodiment can ensure the timeliness of the query result by repeatedly querying whether the identifier of the dependent container is mapped to the startup identifier, and promptly start any container after the startup completion identifier of the dependent container is queried, thereby improving the control efficiency of sequential startup of the containers.
[0067] Further, based on the above embodiments, before the startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, it includes:
[0068] The configuration file is generated according to the identifier of the dependent container that any container depends on when starting any container, which is configured when any container is created.
[0069] The process of creating any container will configure the dependent container that the container depends on to start. The configuration file contains the identifier of the dependent container that the container depends on to start. The startup tool of any container can determine the identifier of the dependent container of any container by accessing the configuration file.
[0070] In this embodiment, the startup tool determines the identifier of the dependent container of any container through the configuration file in any container, and then queries the startup status of the dependent container according to the identifier of the dependent container of any container, thereby realizing the control process of starting the containers according to the startup sequence.
[0071] Based on the above control of the startup tool over the container startup process, see Figure 2 The virtualized container startup method provided in this embodiment (1) groups service containers that have startup dependencies with each other into a set (e.g., Container1, Container2, ..., Containern), wherein each container is mounted and shares the same shared storage volume (container.meta, i.e., shared storage space). (2) provides a unified container command startup tool, which provides three callback interfaces:
[0072] The pre-startup callback interface is a callback interface for pre-startup dependencies. This interface returns a list of other service containers that the current container depends on for startup, and is used to predict and wait for the startup of dependent containers to be completed.
[0073] The execution callback interface is a callback interface for executing the start command. The interface returns the start command of the current container and is used to start the container.
[0074] The notification callback interface is a notification callback interface for the completion of the startup of the current container to be started, and is used to register with the specified directory and file when the container startup is completed.
[0075] For shared storage, Figure 2 It also provides (3) a set of operation and maintenance web interfaces, which displays the startup dependencies between containers by reading the directories and files of the shared storage volume. Specifically, Figure 3A flowchart of a virtualized container information maintenance method provided in this embodiment is shown in FIG. Figure 3 , the virtualized container information maintenance method includes:
[0076] Step 301: obtaining a startup sequence corresponding to any container in a container set configured through an interactive interface when starting each container in the container set, and storing an identifier of any container and the startup sequence corresponding to any container in a dependent container relationship in a shared storage space;
[0077] The startup order corresponding to any one of the containers is determined according to the container on which each container is dependent when each container in the container set is created, configured for starting each container; the shared storage space is shared by the container set to which the any one of the containers belongs; and the container set includes at least two containers having a startup order.
[0078] The interactive interface refers to a human-computer interactive interface (e.g., a WEB interface), through which the user can write the startup sequence of the container, which is stored in the dependent container relationship by the shared storage space. It is understandable that the user writes the startup sequence to the dependent container configured when the container is created. If the startup sequence written by the user is different from the startup sequence determined according to the dependent container configured for each container, an error will occur during the startup process, resulting in termination of the sequential startup.
[0079] In this embodiment, the dependent container relationship in the shared storage space is stored and edited through an interactive interface, which provides a way for users to uniformly manage the shared storage space and realizes the management of the dependent container relationship in the shared storage space.
[0080] The embodiment provides a method for maintaining virtualized container information, and a startup tool is configured for each container. After the startup tool obtains the identifier of the dependent container of any container in which it is located, or after the startup tool queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-start callback interface, if the identifier of the dependent container is queried from the shared storage space through the pre-start callback interface to complete the startup identifier, then the any container is started by executing the callback interface. Through the shared storage space shared by the container set to which any container belongs, the startup tool can query the dependent container, query the startup status of the dependent container, and write the startup status of the container through a unified interface, thereby eliminating the need to encapsulate different scripts for the container, achieving standardization of the container startup process, and simplifying the implementation process of sequential startup of containers.
[0081] Furthermore, based on the above embodiment, it also includes:
[0082] Receiving a first query request sent by a startup tool configured in any container through a pre-startup callback interface; the first query request is used to request to query an identifier of a dependent container of any container according to an identifier of the any container;
[0083] querying, from the dependent container relationships stored in the shared storage space, the identifier of a container whose startup sequence is adjacent to the startup sequence of any container and which is started before any container, and using the identifier of the queried container as the identifier of the dependent container of any container;
[0084] The identifier of the dependent container of any container is returned to the startup tool through the pre-startup callback interface.
[0085] In the process of realizing sequential startup of containers, the startup tool interacts with the shared storage space through the pre-startup callback interface to realize the identification of dependent containers and query of the startup status of dependent containers. After receiving the first query request, the shared storage space queries the identification of the dependent container of any container from the dependent container relationship according to the identification of any container, and returns the queried identification of the dependent container to the startup tool through the pre-startup callback interface, so that the startup tool queries the startup status of the dependent container according to the identification of the dependent container, so that after the dependent container is started, the any container is started, and the control of the startup of the container according to the startup sequence is realized.
[0086] Furthermore, based on the above embodiments, it also includes:
[0087] receiving a second query request sent by a startup tool configured in any container through the pre-startup callback interface, wherein the second query request is used to query whether an identifier of a dependent container of any container is mapped to a startup identifier;
[0088] According to the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, query whether the identifier of the dependent container of any container is mapped to the completion startup identifier; if so, send a query response to the startup tool through the pre-startup callback interface; otherwise, do not send the query response to the startup tool; the query response is used to indicate that the query to the dependent container's identifier is mapped to the completion startup identifier.
[0089] After determining the identifier of the dependent container of the any container, the startup tool of any container sends a second query request to the shared storage space according to the identifier of the dependent container. After receiving the second query request, the shared storage space queries whether the dependent container has completed startup according to the identifier of the dependent container and the completed startup identifier stored in advance for each container that has completed startup. After the shared storage space determines that the identifier of the dependent container of the any container is mapped to the completed startup identifier, a query response is returned to the startup tool, so that the startup tool of the any container performs startup control on the any container after receiving the query response.
[0090] It should be noted that, when any container has multiple dependent containers, any container is started only after receiving a query response corresponding to each dependent container.
[0091] In this embodiment, the startup status of dependent containers is queried through the pre-start callback interface. After the startup tool of any container receives the query response corresponding to each dependent container of any container, the startup of any container is controlled, thereby realizing the sequential startup of containers.
[0092] Furthermore, based on the above embodiments, it also includes:
[0093] Receiving a write instruction sent by a startup tool configured in any container through a notification callback interface; the write instruction is used to indicate that a startup flag is written to any container;
[0094] A file in a preset format is written into the folder where any one of the containers in the shared storage space is located, and the file in the preset format is used as a completion start identifier of mapping any one of the containers.
[0095] The startup tool also provides a notification callback interface. When the startup tool detects that any container has completed startup, it writes a startup completion flag to the container through the notification callback interface, so that after any container has completed startup, the startup status of the container can be queried through the shared storage volume. When the container is a dependent container of other containers, the correct startup status can be queried in time to ensure that subsequent containers are started in order.
[0096] In this embodiment, the notification callback interface is used to realize timely update of the startup status of any container after any container completes startup, so that the shared storage space can provide timely updated container status, avoid delays in the startup process due to untimely startup status updates, and ensure the startup efficiency of the containers in sequential startup.
[0097] In general, the methods for starting virtualized containers and maintaining information include the following information:
[0098] When the container is started and callback is made, the startup tool needs to write an empty file finish.ok to the specified directory of the shared storage volume. The corresponding directory path is as follows: / service name / container name / finish.ok; and update its own container information (container status information) in the container.meta file in the root directory of the shared storage volume, such as: the status of the container and the dependent containers, the flag file path, etc. Here, the storage of the flag file and container information is used to determine whether the container has been started and is used for interface visualization and configuration.
[0099] When a callback is made before the container is started, the startup tool needs to read the list of dependent service containers returned by the interface to see whether there is a finish.ok file in the specified container directory under the specified service. If so, it returns true and executes the startup command; otherwise, it returns false and continues to wait.
[0100] Figure 4 See the schematic diagram of the implementation process of orderly starting the container provided in this embodiment. Figure 4 , the process includes the following steps:
[0101] 1. The user presets a container set through the visual interface and configures the startup dependency list of each container. In terms of specific implementation, the startup order of each container in the set can be configured, and multiple containers can be configured in the same order.
[0102] 2. The visual interface interacts with the shared storage area. By parsing the user's preset information, the startup dependency list of each container in the collection is obtained, and then this information is stored in the container.meta file in the shared storage area.
[0103] 3. Before starting the container, the startup tool obtains the current container identifier, such as the name, by reading the environment variables or the specified configuration file in the container.
[0104] 4. Start the tool to query the list of dependent containers of the current container in the container.meta file in the shared storage area. If the current container startup does not depend on other containers, go directly to step 6, otherwise continue with the following steps.
[0105] 5. The startup tool searches the shared storage area for the completion flag file finish.ok of each container according to the list of dependent containers. If one does not exist, wait for 5 seconds and continue to query.
[0106] 6. If the completion flag files that depend on the container exist, call the container's startup command to start the container.
[0107] 7. After the container is started, the startup tool is notified. Notification methods include:
[0108] a. The container provides a probe service, and the startup tool detects whether the service has been started;
[0109] b. After the container is started, the notification interface of the startup tool is called back.
[0110] 8. After the startup tool receives the instruction that the container startup is completed, it writes the startup completion mark file of the container to the shared storage area, such as " / service name 1 / container name 1 / finisho.ok", and updates the container's own information in the container.meta file, such as the status of the container and the dependent containers, the mark file path, etc.
[0111] In summary, the method provided in this embodiment, on the one hand, uses a unified startup tool to encapsulate the startup command of the container and standardizes the startup process of the container; on the other hand, through the communication method of shared storage, it realizes the judgment, waiting and notification recording of the container startup dependency.
[0112] It is understandable that the methods provided in the above embodiments are applicable to Docker Compose and K8S, and are not even limited to Docker, as long as the container provides a startup command callback interface implementation and shared storage mounting.
[0113] Compared with the existing method of starting containers in sequence in Docker Compose, on the one hand, the method provided in this embodiment standardizes the container startup process through a unified startup tool (specifically, the startup tool in each embodiment of the present application exposes three interface callbacks to the outside, which can unify and standardize the callback processing of container pre-startup dependency judgment and waiting, startup command execution, startup completion notification and recording). On the other hand, the method provided in this embodiment allows mutually dependent containers to share the same storage volume, and manages startup dependencies through storage volume directory files combined with WEB display, which is more concise, intuitive and easy to maintain.
[0114] Compared with the existing Kubernetes Init container solution, first of all, the method provided in this embodiment does not require the container to exit the service after the startup is completed. That is, after the container completes the startup completion notification, it can enter continuous online operation and provide services. Secondly, the method provided in this embodiment can be directly used in the Pod to realize the startup sequence of multiple containers in the pod, and can also realize the startup sequence control of containers in different services and different pods, with finer control granularity. Finally, the method provided in this embodiment does not need to rely on the initial container (init-container) concept used in Kubernetes, has few limitations, and can be used across platforms.
[0115] Figure 5 This is a structural block diagram of the virtualized container startup device provided in this embodiment, and the virtualized container startup device is applied to the startup tool, see Figure 5 The virtualized container startup device includes an acquisition module 501 and a startup module 502, wherein:
[0116] The acquisition module 501 is used to obtain the identifier of the dependent container of any container from the configuration file of any container, or query the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-start callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence;
[0117] The startup module 502 is used to query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-startup callback interface according to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, and then send a startup command to any of the containers by executing the callback interface; otherwise, do not send the startup command to any of the containers.
[0118] The virtualized container startup device provided in this embodiment is applicable to the virtualized container startup methods provided in the above embodiments, and will not be described in detail here.
[0119] An embodiment of the present invention provides a virtualized container startup and information maintenance device, and a startup tool is configured for each container. After the startup tool obtains the identifier of the dependent container of any container in which it is located, or after the startup tool queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface, if the startup identifier is completed by querying the identifier mapping of the dependent container from the shared storage space through the pre-startup callback interface, then the any container is started by executing the callback interface. Through the shared storage space shared by the container set to which any container belongs, the startup tool can query the dependent container, query the startup status of the dependent container, and write the startup status of the container through a unified interface, so that there is no need to encapsulate different scripts for the container, thereby realizing the standardization of the container startup process and simplifying the implementation process of sequential startup of containers.
[0120] Optionally, it also includes:
[0121] After detecting that the startup of any container is completed, a file in a preset format is written to the folder where any container is located in the shared storage space through a notification callback interface, and the file in the preset format is used as a completion startup identifier of the mapping of any container.
[0122] Optionally, querying whether the dependent container identifier is mapped to a startup identifier through the pre-startup callback interface until the dependent container identifier is mapped to a startup identifier, comprises:
[0123] The pre-start callback interface is used to query whether the dependent container identifier is mapped to the start identifier at preset time intervals until the dependent container identifier is mapped to the start identifier.
[0124] Optionally, before the startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, the method further includes:
[0125] The configuration file is generated according to the identifier of the dependent container that any container depends on when starting any container, which is configured when any container is created.
[0126] Figure 6 This is a structural block diagram of the virtualized container information maintenance device provided in this embodiment. The virtualized container information maintenance device is applied to a shared storage space. Figure 6 The virtualized container information maintenance device includes a storage module 601, wherein:
[0127] The storage module 601 is used to obtain the startup sequence corresponding to any container in the container set when starting each container in the container set configured through the interactive interface, and store the identifier of any container and the startup sequence corresponding to any container in the dependent container relationship in the shared storage space;
[0128] The startup order corresponding to any one of the containers is determined according to the container on which each container is dependent when each container in the container set is created, configured for starting each container; the shared storage space is shared by the container set to which the any one of the containers belongs; and the container set includes at least two containers having a startup order.
[0129] The virtualized container information maintenance method provided in this embodiment is applicable to the virtualized container information maintenance method provided in the above embodiments, and will not be described in detail here.
[0130] An embodiment of the present invention provides a virtualized container startup and information maintenance device, and a startup tool is configured for each container. After the startup tool obtains the identifier of the dependent container of any container in which it is located, or after the startup tool queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface, if the startup identifier is completed by querying the identifier mapping of the dependent container from the shared storage space through the pre-startup callback interface, then the any container is started by executing the callback interface. Through the shared storage space shared by the container set to which any container belongs, the startup tool can query the dependent container, query the startup status of the dependent container, and write the startup status of the container through a unified interface, so that there is no need to encapsulate different scripts for the container, thereby realizing the standardization of the container startup process and simplifying the implementation process of sequential startup of containers.
[0131] Optionally, it also includes:
[0132] Receiving a first query request sent by a startup tool configured in any container through a pre-startup callback interface; the first query request is used to request to query an identifier of a dependent container of any container according to an identifier of the any container;
[0133] querying, from the dependent container relationships stored in the shared storage space, the identifier of a container whose startup sequence is adjacent to the startup sequence of any container and which is started before any container, and using the identifier of the queried container as the identifier of the dependent container of any container;
[0134] The identifier of the dependent container of any container is returned to the startup tool through the pre-startup callback interface.
[0135] Optionally, it also includes:
[0136] receiving a second query request sent by a startup tool configured in any container through the pre-startup callback interface, wherein the second query request is used to query whether an identifier of a dependent container of any container is mapped to a startup identifier;
[0137] According to the mapping relationship between the completion startup identifier written into the shared storage space by the container that has completed startup in the container set and the identifier of the container that has completed startup, query whether the identifier of the dependent container of any container is mapped to the completion startup identifier; if so, send a query response to the startup tool through the pre-startup callback interface; otherwise, do not send the query response to the startup tool; the query response is used to indicate that the query to the dependent container's identifier is mapped to the completion startup identifier.
[0138] Optionally, it also includes:
[0139] Receiving a write instruction sent by a startup tool configured in any container through a notification callback interface; the write instruction is used to indicate that a startup flag is written to any container;
[0140] A file in a preset format is written into the folder where any one of the containers in the shared storage space is located, and the file in the preset format is used as a completion start identifier of mapping any one of the containers.
[0141] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702 and the memory 703 communicate with each other through the communication bus 704. The processor 701 may call the logic instructions in the memory 703 to execute the following method:
[0142] The startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, or queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence; according to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container in the container set that has completed startup and the identifier of the container that has completed startup, query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-startup callback interface, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, send a startup command to any container through the execution callback interface, otherwise, do not send the startup command to any container;
[0143] Alternatively, a startup sequence corresponding to any container in a container set configured through an interactive interface when each container in the container set is started is obtained, and an identifier of any container and a startup sequence corresponding to any container are stored in a dependent container relationship in a shared storage space; wherein the startup sequence corresponding to any container is determined according to a container on which each container depends when each container in the container set is created, configured for each container; wherein the shared storage space is shared by the container set to which the any container belongs; and the container set includes at least two containers having a startup sequence.
[0144] In addition, the logic instructions in the above-mentioned memory 703 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0145] Furthermore, an embodiment of the present invention discloses a computer program, wherein the computer program includes a computer program stored on a non-transitory readable storage medium, wherein the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above method embodiments, for example, including:
[0146] The startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, or queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence; according to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container in the container set that has completed startup and the identifier of the container that has completed startup, query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-startup callback interface, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, send a startup command to any container through the execution callback interface, otherwise, do not send the startup command to any container;
[0147] Alternatively, a startup sequence corresponding to any container in a container set configured through an interactive interface when each container in the container set is started is obtained, and an identifier of any container and a startup sequence corresponding to any container are stored in a dependent container relationship in a shared storage space; wherein the startup sequence corresponding to any container is determined according to a container on which each container depends when each container in the container set is created, configured for each container; wherein the shared storage space is shared by the container set to which the any container belongs; and the container set includes at least two containers having a startup sequence.
[0148] On the other hand, an embodiment of the present invention further provides a non-transitory readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the transmission method provided in the above embodiments is implemented, for example, including:
[0149] The startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, or queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence; according to the identifier of the dependent container and the mapping relationship between the completion startup identifier written into the shared storage space by the container in the container set that has completed startup and the identifier of the container that has completed startup, query whether the identifier of the dependent container is mapped to the completion startup identifier through the pre-startup callback interface, until it is queried that the identifier of the dependent container is mapped to the completion startup identifier, send a startup command to any container through the execution callback interface, otherwise, do not send the startup command to any container;
[0150] Alternatively, a startup sequence corresponding to any container in a container set configured through an interactive interface when each container in the container set is started is obtained, and an identifier of any container and a startup sequence corresponding to any container are stored in a dependent container relationship in a shared storage space; wherein the startup sequence corresponding to any container is determined according to a container on which each container depends when each container in the container set is created, configured for each container; wherein the shared storage space is shared by the container set to which the any container belongs; and the container set includes at least two containers having a startup sequence.
[0151] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0153] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for starting a virtualized container, characterized in that: Applicable to startup tools, including: The startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, or queries the identifier of the dependent container of any container from the dependent container relationship stored in the shared storage space through the pre-startup callback interface according to the identifier of any container; wherein the dependent container is a container whose startup sequence is before any container and whose startup sequence is adjacent to any container; the shared storage space is shared by the container set to which any container belongs; the container set includes at least two containers with a startup sequence; the dependent container relationship records the identifiers of the containers in the container set and the corresponding startup sequence; According to the identifier of the dependent container and the mapping relationship between the completion start identifier written into the shared storage space by the container that has completed start in the container set and the identifier of the container that has completed start, query through the pre-start callback interface whether the identifier of the dependent container is mapped to the completion start identifier, until it is queried that the identifier of the dependent container is mapped to the completion start identifier, send a start command to any of the containers through the execution callback interface, otherwise, do not send the start command to any of the containers; After detecting that the startup of any container is completed, writing a file in a preset format to the folder where any container is located in the shared storage space through a notification callback interface, and using the file in the preset format as a completion startup identifier of the mapping of any container; Before the startup tool configured in any container obtains the identifier of the dependent container of any container from the configuration file of any container, the method includes: The configuration file is generated according to an identifier of a dependent container that is configured when any container is created and that is started and that any container depends on.
2. The method for starting a virtualized container according to claim 1, characterized in that: The querying of whether the dependent container identifier is mapped to a startup identifier through the pre-start callback interface until the dependent container identifier is mapped to a startup identifier includes: The pre-start callback interface is used to query whether the dependent container identifier is mapped to the start identifier at preset time intervals until the dependent container identifier is mapped to the start identifier.
3. A method for maintaining virtualized container information, characterized in that: Applicable to shared storage space, including: Obtaining a startup sequence corresponding to any container in the container set configured through an interactive interface when starting each container in the container set, and storing an identifier of any container and the startup sequence corresponding to any container in a dependent container relationship in a shared storage space; wherein the startup order corresponding to any of the containers is determined according to the container on which each container is dependent when each container in the container set is created, configured for each container; wherein the shared storage space is shared by the container set to which any of the containers belongs; and the container set includes at least two containers having a startup order; Receiving a first query request sent by a startup tool configured in any container through a pre-startup callback interface; the first query request is used to request to query an identifier of a dependent container of any container according to an identifier of the any container; querying, from the dependent container relationships stored in the shared storage space, the identifier of a container whose startup sequence is adjacent to the startup sequence of any container and which is started before any container, and using the identifier of the queried container as the identifier of the dependent container of any container; Returning the identifier of the dependent container of any container to the startup tool through the pre-startup callback interface; Receiving a write instruction sent by a startup tool configured in any container through a notification callback interface; the write instruction is used to indicate that a startup flag is written to any container; A file in a preset format is written into the folder where any one of the containers in the shared storage space is located, and the file in the preset format is used as a completion start identifier of mapping any one of the containers.
4. The method for maintaining virtualized container information according to claim 3, characterized in that: Also includes: receiving a second query request sent by a startup tool configured in any container through the pre-startup callback interface, wherein the second query request is used to query whether an identifier of a dependent container of any container is mapped to a startup identifier; According to the mapping relationship between the completion start identifier written into the shared storage space by the container that has completed start in the container set and the identifier of the container that has completed start, query whether the identifier of the dependent container of any container is mapped to the completion start identifier, and if so, send a query response to the start tool through the pre-start callback interface, otherwise, do not send the query response to the start tool; The query response is used to indicate that the query to the dependent container's identifier mapping completes the start identifier.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the virtualization container startup method according to any one of claims 1 to 2 are implemented, or when the processor executes the program, the steps of the virtualization container information maintenance method according to any one of claims 3 to 4 are implemented.
6. A non-transitory readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the virtualization container startup method according to any one of claims 1 to 2 or the steps of the virtualization container information maintenance method according to any one of claims 3 to 4 are implemented.
Citation Information
Patent Citations
Container entry program operation method, system and device and storage medium
CN107368339A
Container monitoring method, device and apparatus and computer readable storage medium
CN110134496A
Techniques for managing software container dependencies
US20180246729A1
Distributed file storage system supporting accesses from multiple container hosts
US20190065096A1
