A method, device, medium and equipment for container port management

The container port is managed through a combined data structure of tree structure and linked list structure, which solves the problems of port conflicts and resource release, and realizes efficient allocation and release of ports, improving the efficiency and accuracy of container management.

CN111966442BActive Publication Date: 2024-12-03凌川峰(贵州)信息技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910417332.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-05-20
Publication Date
2024-12-03
Estimated Expiration
2039-05-20

AI Technical Summary

Technical Problem

When creating multiple containers, it is difficult for users to manage mapped ports on the host, which easily leads to port conflicts and is difficult to effectively release port resources that are no longer used.

Method used

A combined data structure of tree structure and linked list structure is adopted to manage port allocation and release through container type and pre-allocated ports, ensuring accurate marking and querying of port status, avoiding port conflicts, and timely releasing garbage ports.

Benefits of technology

It realizes efficient port management, avoids port conflicts, improves port usage efficiency, and ensures the accuracy and efficiency of the rapid allocation and release process of containers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111966442B_ABST
    Figure CN111966442B_ABST
Patent Text Reader

Abstract

The present invention discloses a container port management method, which includes obtaining a port allocation request of a container, wherein the port allocation request carries allocation request parameters; selecting a port in an idle state according to the allocation request parameters, and allocating the selected port to the container; marking the state of the selected port as used; dividing the ports into different port sets according to container types, allocating ports to the containers according to the container types, and storing a mapping relationship between a container identifier and a selected port, as well as the selected port in different data structures. When allocating ports to the containers, the idle ports can be found quickly and accurately, thereby realizing convenient and rapid management of the ports and avoiding port conflicts when allocating ports to the containers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to the management of computer ports. Background Art

[0002] When using containers, if the access mode of the existing container bridge is set, the container IP needs to be mapped to the corresponding port of the host to allow external network access. In the existing technology, the port mapped by the container IP needs to be specified by the user when creating the container. When the user creates multiple containers, it is no longer known which ports in the host have been mapped by the container IP. At this time, when specifying the mapping port for the new container, if the specified port is already occupied, it is easy to cause port conflicts. Summary of the invention

[0003] In order to solve the above technical problems, the present invention provides a method for managing container ports, the method comprising:

[0004] Obtain a port allocation request of a container, the port allocation request carrying an allocation request parameter; select a port in an idle state according to the allocation request parameter, and allocate the selected port to the container; mark the state of the selected port as used;

[0005] The allocation request parameters include a container type and / or a pre-allocated port; and selecting a port in an idle state according to the allocation request parameters includes one of the following methods:

[0006] When the allocation request parameter includes a container type, selecting a port in an idle state from a predetermined port set corresponding to the container type according to the container type;

[0007] When the allocation request parameter includes a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port in the idle state is selected from all ports;

[0008] When the allocation request parameters include the container type and the pre-allocated port, if the status of the pre-allocated port is idle, the pre-allocated port is selected; if the status of the pre-allocated port is used, a port with an idle status is selected from a predetermined port set corresponding to the container type according to the container type.

[0009] The method further includes:

[0010] Determining a mapping relationship between an identifier of a container and an identifier of the selected port;

[0011] The mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port are stored in a preset data structure.

[0012] Storing the mapping relationship between the container identifier and the selected port identifier and the selected port identifier in a preset data structure includes: the preset data structure includes a tree structure and a linked list structure; storing the mapping relationship between the container identifier and the selected port identifier in the tree structure, and storing the selected port identifier in the linked list structure.

[0013] The linked list structure includes more than one linked list, and different linked lists correspond to different container types; storing the identifier of the selected port in the linked list structure includes: determining the container type of the container, and storing the identifier of the selected port in the linked list corresponding to the container type of the container.

[0014] The method further includes:

[0015] receiving a container destruction notification, wherein the container destruction notification includes an identifier of the container;

[0016] Searching for the node where the container identifier is located in the tree structure, and determining the port identifier and container type corresponding to the container identifier according to the node;

[0017] Delete the node where the container's identifier is located in the tree structure;

[0018] Determine the linked list corresponding to the container type, and delete the node where the port identifier is located from the linked list;

[0019] Mark the state of the port as idle.

[0020] The method further includes:

[0021] Scan the tree structure and traverse the identifiers of the containers in the tree structure;

[0022] Check whether the identifier of each container exists in the container engine;

[0023] If the identifier of a certain container does not exist in the container engine, it is determined that the port indicated by the node where the identifier of the container is located is a garbage port;

[0024] Delete the node where the identifier of this container is located in the tree structure;

[0025] Determine a linked list corresponding to the container type of the container, delete the node where the identifier of the garbage port is located in the linked list; and mark the state of the garbage port as idle.

[0026] When adding, deleting, querying, and traversing the tree structure and / or linked list structure, a single-threaded access restriction is set for the tree structure and the linked list structure, and the single-threaded access restriction is lifted for the tree structure and the linked list structure after the operation is completed.

[0027] The present invention also provides a container port management device, comprising:

[0028] Receiving module: used to receive the port allocation request of the container;

[0029] Port selection module: based on the allocation request parameters carried in the port allocation request, selects a port that is in the idle state and allocates the selected port to the container;

[0030] Port status marking module: marks the status of the selected port as used;

[0031] The allocation request parameters include the container type and / or the pre-allocated port;

[0032] Selecting a port in an idle state according to the allocation request parameters includes one of the following methods:

[0033] When the allocation request parameter includes a container type, selecting a port in an idle state from a predetermined port set corresponding to the container type according to the container type;

[0034] When the allocation request parameter includes a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port in the idle state is selected from all ports;

[0035] When the request information includes the container type and the pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port with an idle state is selected from a predetermined port set corresponding to the container type according to the container type.

[0036] The device also includes:

[0037] Mapping relationship establishment module: determines the mapping relationship between the container identifier and the selected port identifier;

[0038] Storage module: stores the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure.

[0039] Storing the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure includes:

[0040] The preset data structure includes a tree structure and a linked list structure; the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure, and the identifier of the selected port is stored in the linked list structure.

[0041] The linked list structure includes more than one linked list, and different linked lists correspond to different container types;

[0042] Storing the identifier of the selected port in the linked list structure includes: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.

[0043] The device also includes:

[0044] The receiving module is further used to receive a container destruction notification, where the container destruction notification includes an identifier of the container;

[0045] Scanning module: searching for the node where the container identifier is located in the tree structure, and determining the identifier of the port corresponding to the container identifier and the container type according to the node;

[0046] Storage module: delete the node where the container identifier is located in the tree structure;

[0047] Determine the linked list corresponding to the container type, and delete the node where the port identifier is located from the linked list;

[0048] The port status marking module marks the status of the port as idle.

[0049] The device also includes:

[0050] Scanning module: scans the tree structure and traverses the identifiers of the containers in the tree structure;

[0051] Query module: queries whether the identifier of each container exists in the container engine;

[0052] If the identifier of a certain container does not exist in the container engine, it is determined that the port indicated by the node where the identifier of the container is located is a garbage port;

[0053] Delete the node where the identifier of this container is located in the tree structure;

[0054] Determine the linked list corresponding to the container type of the container, and delete the node where the identifier of the garbage port is located in the linked list;

[0055] Mark the state of the junk port as free.

[0056] When adding, deleting, querying, and traversing operations are performed on the tree structure and / or linked list structure, single-thread access restrictions are set on the tree structure and linked list structure, and the single-thread access restrictions are released on the tree structure and linked list structure after the operation is completed.

[0057] A computer-readable medium stores computer-readable instructions, which can be executed by a processor to implement the above method.

[0058] A computer device comprises a processor, a memory and a computer program stored in the memory, wherein the processor implements the steps of the above method when executing the computer program. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0060] Figure 1 is a flow chart of a container port management method;

[0061] Figure 2 It is a binary tree diagram;

[0062] Figure 3 It is a schematic diagram of the linked list structure;

[0063] Figure 4 It is a structural diagram of a container port management device. DETAILED DESCRIPTION

[0064] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the technical scheme 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 in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. It should be noted that the embodiments in this application and the features in the embodiments can be combined with each other arbitrarily without conflict.

[0065] like Figure 1 As shown, the container port management method includes:

[0066] Step 101, obtaining a port allocation request of a container, the port allocation request carrying an allocation request parameter; receiving a port allocation request of a container, the port allocation request including a container identifier, which is generally a container ID, and may also include the number of ports applied for allocation. For example, if some containers need to map multiple ports, the number of ports applied for is carried in the port allocation request parameter, and the system allocates ports to the container according to the number of ports in the port allocation application parameter;

[0067] Step 102, selecting a port in an idle state according to the allocation request parameters, and allocating the selected port to the container; specifically, in the initial stage of the system operation, all available ports may be initialized, and the states of all ports may be marked as idle;

[0068] Step 103, marking the state of the selected port as used. After selecting an available port for the container and allocating the selected port to the container, the state of the selected port is marked as used to prevent it from being selected again and allocated to other containers, causing port conflicts.

[0069] The container port allocation request parameters may include container type and / or pre-allocated port. The container type is a classification of the container according to its function, such as load balancing container and web container. Of course, the container type in this embodiment may also be empty. In the specific implementation, the container port may be planned in advance, and the ports of a certain number segment may be used as a port set. The allocable ports may be divided into multiple port sets with different number segments, and the ports may be allocated to the container in the specified port set according to the type of container. For example, the available ports may be divided into port sets such as [3000-4000], [6000-7000], and [9000-10000]. Then, the load balancing container may be specified to allocate ports in the [3000-4000] port set, and the web container may be assigned ports in the [6000-7000] port set. If the container type is empty in the container port application, the port may be allocated from all available ports. The above-mentioned method of allocating ports may be specified or randomly selected.

[0070] The container port allocation request parameters also include pre-allocated ports, that is, when the container is created, in the port allocation request for applying for a port for the container, one or more ports are preferentially specified for the container and included in the container port allocation request parameters.

[0071] Selecting a port in an idle state according to the allocation request parameters includes one of the following methods:

[0072] When the allocation request parameter includes the container type, a port in the idle state is selected from the predetermined port set corresponding to the container type according to the container type; if the allocation request parameter only includes the container type, the system selects a port in the idle state from the port set corresponding to the container type according to the container type and allocates it to the container. For example, if the container type is web type, a port in the idle state is selected from the [6000-7000] port set and allocated to the container;

[0073] When the allocation request parameters include a pre-allocated port, if the status of the pre-allocated port is idle, the pre-allocated port is selected; if the status of the pre-allocated port is used, a port with an idle status is selected from all ports; if the allocation request parameters only include a pre-allocated port, such as port 80, the system will first query the status of port 80. If the status of port 80 is idle, port 80 is allocated to the container. If the status of port 80 is used, it means that the port has been allocated to other containers. The system will query all ports for a port with an idle status and randomly select a port to allocate to the container.

[0074] When the allocation request parameters include the container type and the pre-allocated port, if the status of the pre-allocated port is idle, the pre-allocated port is selected; if the status of the pre-allocated port is used, a port with an idle status is selected from the predetermined port set corresponding to the container type according to the container type. If the allocation request parameters include the container type and the pre-allocated port, for example, the container type is a web type, and the pre-allocated port is port 8001, the system first queries whether the status of port 8001 is idle. If the status of port 8001 is idle, port 8001 is allocated to the container. If the status of port 8001 is used, according to the container type being a web type, a port with an idle status is selected from the [6000-7000] port set and allocated to the container; the pre-allocated port may also be included in the port set corresponding to the port type.

[0075] After allocating a port to a container, the container port management method further includes:

[0076] Step 104, determine the mapping relationship between the identifier of the container and the identifier of the selected port; store the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure. The identifier of the container is generally the container ID, which is the unique identifier of the container, and the identifier of the port refers to the port number; after the port is assigned to the container, the relationship between the container ID and the selected port number is recorded, and the mapping relationship between the container ID and the selected port and the selected port are stored in a preset data structure, and the data structure can be any form of data structure, which is not limited here.

[0077] The mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port are stored in a preset data structure, including: the preset data structure includes a tree structure and a linked list structure; the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure, and the identifier of the selected port is stored in the linked list structure. According to the features of the present invention, the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure. For example, in this embodiment, a binary tree data structure is used. The binary tree is as follows: Figure 2 As shown. The binary tree data structure facilitates the system to query by container id, improving the query speed; in the binary tree, 201 is the first node of the binary tree, 202 is the second node, 203 is the third node, and so on; each node of the binary tree corresponds to the identifier of a container, including key and value, the key is the container id, the value is the container type of the container and the identifier of the port mapped by the container, when it is necessary to list the existing container ids and the ports mapped by the existing container ids, the results can be quickly obtained by traversing the binary tree. The nodes in the binary tree are arranged according to the container id, and when adding or deleting nodes, the binary tree itself is maintained without human intervention.

[0078] The identifier of the selected port is stored in a linked list structure, such as Figure 3 As shown, the linked list structure 30 includes more than one linked list, and different linked lists correspond to different container types; for example, in the figure, according to the container type, the linked list structure 30 includes three linked lists, namely linked list 301, linked list 302, and linked list 303, which correspond to different container types, for example, linked list 301 corresponds to a load balancing container, linked list 302 corresponds to a web container, and linked list 303 corresponds to other types of containers. Each node in the linked list corresponds to a port identifier of this type, for example, linked list 301 corresponds to a load balancing container, and the corresponding port set of this type of container is [3000-4000]. In the [3000-4000] port set, the port numbers of the used ports are 3001-3006, node 3011 represents port number 3001, node 3012 represents port number 3002, and so on, node 3013 represents port number 3006. Link list 302 corresponds to the web class container. The port set corresponding to this container type is [6000-7000]. The port numbers of the used ports in this port set are 6006-6028. Then, in link list 302, node 3021 represents port number 6006, node 3022 represents port number 6007, and so on. Node 3023 represents port number 6028.

[0079] Storing the selected port identifier in the linked list structure includes: determining the container type of the container, and storing the selected port identifier in the linked list corresponding to the container type of the container. For example, if a new web-type container is created, the system allocates ports in the [6000-7000] port set according to the type of the container, and after establishing a mapping relationship, when storing the port number mapped by the container in the linked list structure, first find the linked list corresponding to the container type according to the container type, and then Figure 3 The linked list 302 corresponds to the web class container, and the port number mapped by the container is stored in the linked list. The linked list structure lists the used ports. The linked list data structure is convenient for querying the used ports. For example, when querying the status of a port, it is only necessary to query whether the port is in the used port linked list. If it is in the used port linked list, it means that the port is a used port. If it is no longer in the used port linked list, it means that the port is a free port. At the same time, it is convenient for adding and deleting used ports. Each node in the linked list is a used port number. In this method, the selected port is also stored in the linked list data structure corresponding to the container type according to the container type. When querying the port status, it is not necessary to traverse all the linked list data structures. It is only necessary to query the linked list structure corresponding to the container type. When there are many containers in the system and a large number of used ports, the query speed can be doubled by this method, saving time and reducing system overhead.

[0080] The method further includes:

[0081] receiving a container destruction notification, wherein the container destruction notification includes a container identifier;

[0082] Searching for the node where the container identifier is located in the tree structure, and determining the port identifier and container type corresponding to the container identifier according to the node;

[0083] Delete the node where the container's identifier is located in the tree structure;

[0084] Determine the linked list structure corresponding to the container type, and delete the node where the port identifier is located from the linked list structure;

[0085] Mark the state of the port as idle.

[0086] During the use of a container, it may no longer be used for various reasons and needs to be destroyed. After the container is destroyed, the port occupied by the container needs to be released in time so that ports can be allocated to other containers. When the container is destroyed, a container destruction notification is sent. After the system receives the container destruction notification, it first searches the binary tree according to the container ID to find the node corresponding to the container ID, determines the port number corresponding to the container ID and the type of the container, then deletes the node corresponding to the container ID in the binary tree, and at the same time finds the linked list corresponding to the container type according to the container type, and deletes the node corresponding to the port identifier corresponding to the container in the linked list.

[0087] The method further includes:

[0088] Scan the tree structure and traverse the identifiers of the containers in the tree structure;

[0089] Check whether the identifier of each container exists in the container engine;

[0090] If the identifier of a certain container does not exist in the container engine, it is determined that the port indicated by the node where the identifier of the container is located is a garbage port;

[0091] Delete the node where the identifier of this container is located in the tree structure;

[0092] Determine the linked list corresponding to the container type of the container, and delete the node where the identifier of the garbage port is located in the linked list;

[0093] Mark the state of the junk port as free.

[0094] When deleting a container, a notification will be sent to the system, prompting that the container has been deleted and the port occupied by the container needs to be released. However, in the process of deleting the node corresponding to the container id in the binary tree and the node corresponding to the port number corresponding to the container id in the linked list structure, an interruption occurred, such as a server crash or power failure restart, resulting in the incomplete operation of the binary tree and the linked list structure, and the node corresponding to the container id and the node in the linked list structure corresponding to the port identifier corresponding to the container id are not deleted in the above data structure, which causes the port to be marked as used, but there is actually no mapping relationship with any container, resulting in a garbage port. This method scans the binary tree, traverses the container id stored in the binary tree, and queries whether each container id exists in the container engine. If it exists, it means that the container is in use. If it does not exist, it means that the container has been deleted, then the port corresponding to the container id is a garbage port, so the node corresponding to the container id is deleted in the binary tree, and the node corresponding to the port identifier corresponding to the container id is deleted in the linked list structure at the same time, and the port is marked as idle, which can be mapped by other containers. In order to find junk ports in the system more timely and improve port usage efficiency, the above binary tree can be scanned regularly to release junk ports in time.

[0095] In any of the above embodiments, when adding, deleting, querying, and traversing operations are performed on a tree structure and / or a linked list structure, a single-thread access restriction is set for the tree structure and the linked list structure, and the single-thread access restriction is lifted for the tree structure and the linked list structure after the operation is completed. In a specific implementation, while operating a tree structure or a linked list structure, a single-thread access restriction is set for the tree structure and the linked list structure, such as adding a code lock to the tree structure and the linked list structure, the purpose of which is to protect the binary tree or linked list structure and ensure that the operations on the two are consistent. For example, when deleting a binary tree node, it is necessary to lock the binary tree and the used port linked list at the same time, delete the binary tree node, and delete the node corresponding to the port identifier corresponding to the binary tree node in the linked list structure at the same time, to ensure the consistency of the data structure content, to avoid other threads accessing the linked list structure and changing the data in the linked list when operating the binary tree, resulting in inconsistent data in the two data structures.

[0096] Through the above embodiments, it can be seen that the method divides the ports into different port sets according to the container type, allocates ports to the containers according to the container type, and stores the mapping relationship between the container id and the selected port, as well as the selected port in different data structures. When allocating ports to the containers, the free ports can be quickly and accurately found, thereby realizing convenient and fast management of the ports and avoiding port conflicts when allocating ports to the containers. At the same time, when the container is destroyed, the container id is first found in the binary tree data structure, and the type of the container and the mapped port can be quickly determined through the node corresponding to the container id, and then the unused ports are released in time in the linked list corresponding to the container type. Even if a downtime or power failure occurs during the port release process, resulting in an interruption of the port release operation and a garbage port, the system can also find the garbage port in time by traversing the id of the built container in the binary tree and querying whether the container id exists in the container engine, thereby improving the port utilization efficiency.

[0097] like Figure 4 As shown, a container port management device includes:

[0098] Receiving module: used to receive container port allocation requests;

[0099] Port selection module: based on the allocation request parameters carried in the container port allocation request, selects a port that is in an idle state and allocates the selected port to the container;

[0100] Port status marking module: marks the status of the selected port as used.

[0101] The allocation request parameters include the container type and / or the pre-allocated port;

[0102] Selecting a port in an idle state according to the allocation request parameters includes one of the following methods:

[0103] When the allocation request parameter includes a container type, selecting a port in an idle state from a predetermined port set corresponding to the container type according to the container type;

[0104] When the allocation request parameter includes a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port in the idle state is selected from all ports;

[0105] When the request information includes the container type and the pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port with an idle state is selected from a predetermined port set corresponding to the container type according to the container type.

[0106] The container port management device also includes:

[0107] Mapping relationship establishment module: determines the mapping relationship between the container identifier and the selected port identifier;

[0108] Storage module: stores the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure.

[0109] Storing the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure includes:

[0110] The preset data structure includes a tree structure and a linked list structure; the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure, and the identifier of the selected port is stored in the linked list structure.

[0111] The linked list structure includes more than one linked list, and different linked lists correspond to different container types;

[0112] Storing the identifier of the selected port in the linked list structure includes: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.

[0113] The container port management device also includes:

[0114] Receiving module: also used to receive a container destruction notification, where the container destruction notification includes an identifier of the container;

[0115] Scanning module: searches for the node where the container identifier is located in the tree structure, and determines the port identifier and container type corresponding to the container identifier based on the node;

[0116] The storage module deletes the node where the identifier of the container is located in the tree structure;

[0117] Determine the linked list corresponding to the container type, and delete the node where the port identifier is located from the linked list;

[0118] The port status marking module marks the status of the port as idle.

[0119] The container port management device also includes:

[0120] Scanning module: scans the tree structure and traverses the identifiers of the containers in the tree structure;

[0121] Query module: queries whether the identifier of each container exists in the container engine;

[0122] If the identifier of a container does not exist in the container engine, it is determined that the port indicated by the node where the identifier of the container is located is a garbage port;

[0123] Delete the node where the identifier of this container is located in the tree structure;

[0124] Determine the linked list corresponding to the container type of the container, and delete the node where the identifier of the garbage port is located in the linked list;

[0125] Mark the state of the junk port as free.

[0126] When adding, deleting, querying, and traversing the tree structure and / or linked list structure, a single-threaded access restriction is set for the tree structure and the linked list structure, and the single-threaded access restriction is lifted for the tree structure and the linked list structure after the operation is completed.

[0127] A computer-readable medium stores computer-readable instructions, which can be executed by a processor to implement the above method.

[0128] A computer device comprises a processor, a memory and a computer program stored in the memory, and the steps of the above method are implemented when the processor executes the computer program.

[0129] The contents described above may be implemented individually or in combination in various ways, and these variations are all within the protection scope of the present invention.

[0130] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, devices (equipment), or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program codes. Computer storage media include volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data), including but not limited to RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassette, magnetic tape, disk storage or other magnetic storage device, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that communication media generally contain computer-readable instructions, data structures, program modules or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0131] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (devices) and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as a combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 Functions specified in one or more boxes

[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 In this article, the terms "comprises", "comprising" or any other variant thereof are intended to cover non-exclusive inclusion, so that an article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such article or device. In the absence of further restrictions, the elements defined by the sentence "comprising..." do not exclude the presence of other identical elements in the article or device including the elements.

[0133] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0134] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is intended to include these modifications and variations.

Claims

1. A container port management method, characterized in that: Obtaining a port allocation request of a container, where the port allocation request carries an allocation request parameter; Selecting a port in an idle state according to the allocation request parameters, and allocating the selected port to the container; Marking the state of the selected port as used; The allocation request parameters include container types and / or pre-allocated ports, wherein the container types are classifications of the containers according to their functions, and different container types correspond to different pre-allocated port sets; Selecting a port in an idle state according to the allocation request parameter includes one of the following methods: When the allocation request parameter includes a container type, selecting a port in an idle state from a predetermined port set corresponding to the container type according to the container type; When the allocation request parameter includes a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port in the idle state is selected from all ports; When the allocation request parameters include a container type and a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port with an idle state is selected from a predetermined port set corresponding to the container type according to the container type.

2. The container port management method according to claim 1, characterized in that: Also includes: Determining a mapping relationship between the identifier of the container and the identifier of the selected port; The mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port are stored in a preset data structure.

3. The container port management method according to claim 2, characterized in that: Storing the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure includes: The preset data structure includes a tree structure and a linked list structure; the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure, and the identifier of the selected port is stored in the linked list structure.

4. The container port management method according to claim 3, characterized in that: The linked list structure includes more than one linked list, and different linked lists correspond to different container types; Storing the identifier of the selected port in a linked list structure includes: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.

5. The container port management method according to claim 4, characterized in that: Also includes: receiving a container destruction notification, wherein the container destruction notification includes an identifier of the container; Searching the tree structure for a node where the identifier of the container is located, and determining the identifier of the port corresponding to the identifier of the container and the container type according to the node; Deleting the node where the identifier of the container is located in the tree structure; Determine a linked list corresponding to the container type, and delete the node where the identifier of the port is located from the linked list; Mark the state of the port as idle.

6. The container port management method according to claim 4, characterized in that: Also includes: Scan the tree structure and traverse the identifiers of the containers in the tree structure; Check whether the identifier of each container exists in the container engine; If the identifier of a certain container does not exist in the container engine, determining that the port indicated by the node where the identifier of the container is located is a junk port; Deleting the node where the identifier of the container is located in the tree structure; Determine a linked list corresponding to the container type of the container, and delete the node where the identifier of the garbage port is located in the linked list; The state of the junk port is marked as idle.

7. The container port management method according to any one of claims 3 to 6, characterized in that: When adding, deleting, querying, and traversing the tree structure and / or linked list structure, a single-threaded access restriction is set for the tree structure and linked list structure, and the single-threaded access restriction is released for the tree structure and linked list structure after the operation is completed.

8. A container port management device, comprising: Receiving module: used to receive the port allocation request of the container; A port selection module: based on the allocation request parameters carried in the port allocation request, selects a port in an idle state, and allocates the selected port to the container; Port status marking module: marking the status of the selected port as used; The allocation request parameters include container types and / or pre-allocated ports, wherein the container types are classifications of the containers according to their functions, and different container types correspond to different pre-allocated port sets; Selecting a port in an idle state according to the allocation request parameter includes one of the following methods: When the allocation request parameter includes a container type, selecting a port in an idle state from a predetermined port set corresponding to the container type according to the container type; When the allocation request parameter includes a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port in the idle state is selected from all ports; When the allocation request parameters include a container type and a pre-allocated port, if the state of the pre-allocated port is idle, the pre-allocated port is selected; if the state of the pre-allocated port is used, a port with an idle state is selected from a predetermined port set corresponding to the container type according to the container type.

9. The container port management device according to claim 8, characterized in that: Also includes: A mapping relationship establishing module: determining a mapping relationship between the identifier of the container and the identifier of the selected port; Storage module: stores the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure.

10. The container port management device according to claim 9, characterized in that: Storing the mapping relationship between the identifier of the container and the identifier of the selected port and the identifier of the selected port in a preset data structure includes: The preset data structure includes a tree structure and a linked list structure; the mapping relationship between the identifier of the container and the identifier of the selected port is stored in the tree structure, and the identifier of the selected port is stored in the linked list structure.

11. The container port management device according to claim 10, characterized in that: The linked list structure includes more than one linked list, and different linked lists correspond to different container types; Storing the identifier of the selected port in a linked list structure includes: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.

12. The container port management device according to claim 11, characterized in that: Also includes: The receiving module is further configured to receive a container destruction notification, wherein the container destruction notification includes an identifier of the container; Scanning module: searching the tree structure for a node where the identifier of the container is located, and determining the identifier of the port corresponding to the identifier of the container and the container type according to the node; Storage module: deleting the node where the identifier of the container is located in the tree structure; Determine a linked list corresponding to the container type, and delete the node where the identifier of the port is located from the linked list; Port status marking module: marks the status of the port as idle.

13. The container port management device according to claim 11, characterized in that: Also includes: Scanning module: scanning the tree structure and traversing the identifiers of the containers in the tree structure; Query module: queries whether the identifier of each container exists in the container engine; If the identifier of a certain container does not exist in the container engine, determining that the port indicated by the node where the identifier of the container is located is a junk port; Deleting the node where the identifier of the container is located in the tree structure; Determine a linked list corresponding to the container type of the container, and delete the node where the identifier of the garbage port is located in the linked list; The state of the junk port is marked as idle.

14. The container port management device according to any one of claims 10 to 13, characterized in that: When adding, deleting, querying, and traversing the tree structure and / or linked list structure, a single-threaded access restriction is set for the tree structure and linked list structure, and the single-threaded access restriction is released for the tree structure and linked list structure after the operation is completed.

15. A computer-readable medium having computer-readable instructions stored thereon, wherein the computer-readable instructions can be executed by a processor to implement the method according to any one of claims 1 to 7.

16. A computer device comprising a processor, a memory and a computer program stored in the memory, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.