Container command execution method, device, equipment and storage medium
By intercepting and converting container commands, a simulated context environment is generated, which solves the resource imbalance problem caused by container command execution and improves business processing efficiency and user experience.
Patent Information
- Application Number
- CN202010527639.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-10
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-09-24
AI Technical Summary
The command execution method of the existing container requires logging into the container, which leads to resource imbalance in the Pod and affects business processing.
By intercepting the container commands to be executed, converting them into instructions that can be recognized by the target container, and generating a simulation context environment outside the target container, the command results are executed and displayed to avoid directly logging into the container to occupy resources.
There is no need to log in to the container, which avoids resource preemption, improves business processing efficiency, reduces user operation difficulty, and improves user experience.
Smart Images

Figure CN111680288B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a command execution method, device, equipment and computer-readable storage medium for a container. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming into Fintech, and technology is no exception. However, due to the security and real-time requirements of the financial industry, higher requirements are also put forward for the command execution technology of containers. Among them, Kubernetes is an open source platform, referred to as K8S, which is used to manage containerized applications on multiple hosts in the cloud platform. At present, many Internet companies or financial institutions have built container cloud platforms based on Kubernetes in the production environment. Kubernetes provides the command line tool kubectl and its subcommand exec, which are used to log in to the container and interactively execute commands in the container. Pod is the smallest deployable unit that can create and manage Kubernetes computing, consisting of one or more containers. The containers in the Pod have a common operating environment, shared memory, CPU and other resources. Therefore, the current command execution method of the container requires direct login to the container and operation in the real environment of the container, which is easy to cause resource imbalance in the Pod, such as occupying all memory resources or CPU resources in the Pod, thereby affecting the business container and causing business processing failure. Summary of the invention
[0003] The main purpose of the present invention is to propose a container command execution method, device, equipment and computer-readable storage medium, aiming to solve the technical problem that the existing container command execution method requires logging into the container and easily causes resource imbalance in the Pod.
[0004] To achieve the above object, the present invention provides a container command execution method, characterized in that the container command execution method comprises the following steps:
[0005] When a container command to be executed corresponding to the target container is detected, intercepting the container command to be executed;
[0006] Converting the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol;
[0007] The target container instruction is sent to the target container so that the target container executes the operation corresponding to the to-be-executed container command.
[0008] Optionally, after the step of intercepting the container command to be executed when the container command to be executed corresponding to the target container is detected, the method further includes:
[0009] Based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory, a simulated context environment corresponding to the container command to be executed is generated outside the target container, so as to receive and recognize user input instructions or display the execution result of the container command based on the simulated context environment.
[0010] Optionally, after the step of sending the target container instruction to the target container so that the target container executes the operation corresponding to the to-be-executed container command, the step further includes:
[0011] Upon receiving a result instruction fed back by the target container based on the command of the container to be executed, converting the result instruction into a target terminal instruction recognizable by the simulation context environment based on a second data transmission protocol;
[0012] The target terminal command is displayed through the simulated context environment so that the user can understand the operation result corresponding to the target container executing the to-be-executed container command.
[0013] Optionally, the step of generating a simulated context environment corresponding to the container command to be executed outside the target container based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory specifically includes:
[0014] Convert the to-be-executed container command into a container-recognizable command based on the custom abbreviated command, and determine a target working directory for the operation corresponding to the command to be executed on behalf of the container based on the recognizable command;
[0015] Determine whether the target working directory exists in the target container;
[0016] If the target working directory exists in the target container, obtaining the target file corresponding to the target working directory;
[0017] Based on the target environment variable and the target file, a simulation context environment including the target file is generated outside the target container.
[0018] Optionally, after the step of intercepting the container command to be executed when the container command to be executed corresponding to the target container is detected, the method further includes:
[0019] Parsing the container command to be executed, and determining whether the parsed container command to be executed is a command set according to a command keyword, wherein the command set is a set of multiple sub-commands including two or more;
[0020] If the parsed container command to be executed is not a command set, performing a validity check on the container command to be executed;
[0021] When the to-be-executed container command passes the legality check, the step of converting the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol is executed.
[0022] Optionally, if the parsed container command to be executed is not a command set, after the step of performing a legality check on the container command to be executed, the method further includes:
[0023] When the container command to be executed fails to pass the legality check, a reminder message indicating that the current command is illegal is generated and displayed, so as to remind the user that the container command to be executed is an illegal container command.
[0024] Optionally, the command execution method of the container further includes:
[0025] When a setting instruction is received, a target execution instruction in the setting instruction is obtained, and the target execution instruction that passes the execution instruction syntax check is added to a preset instruction whitelist to set the target execution instruction as a legal instruction.
[0026] In addition, to achieve the above-mentioned purpose, the present invention further provides a command execution device for a container, the command execution device for a container comprising:
[0027] A container command interception module, configured to intercept the container command to be executed when a container command to be executed corresponding to a target container is detected;
[0028] An input command conversion module, configured to convert the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol;
[0029] The container command execution module is used to send the target container instruction to the target container so that the target container executes the operation corresponding to the container command to be executed.
[0030] Optionally, the command execution device of the container further includes:
[0031] The container environment simulation module is used to generate a simulation context environment corresponding to the container command to be executed outside the target container based on the target environment variables and the target working directory of the container command to be executed in the target container, so as to receive user input instructions or display the execution result of the container command based on the simulation context environment.
[0032] In addition, to achieve the above-mentioned purpose, the present invention also provides a command execution device for a container, wherein the command execution device for a container comprises: a memory, a processor, and a command execution program for a container stored on the memory and executable on the processor, wherein the command execution program for the container implements the steps of the command execution method for the container as described above when executed by the processor.
[0033] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a command execution program of a container is stored, and when the command execution program of the container is executed by a processor, the steps of the command execution method of the container as described above are implemented.
[0034] The present invention provides a method for executing commands of a container, by intercepting the container command to be executed when a container command to be executed corresponding to a target container is detected; converting the container command to be executed into a target container instruction recognizable by the target container based on a first data transmission protocol; and sending the target container instruction to the target container so that the target container executes the operation corresponding to the container command to be executed. In the above manner, the present invention intercepts the container command to be executed sent to the container, and converts the container to be executed into a target container instruction recognizable by the target container according to the protocol conversion, and then sends the recognizable target container instruction to the target container, so that the target container executes the corresponding operation. There is no need to log in to the container, and there is no need to occupy container resources, thereby avoiding the execution of commands to seize business container resources and causing business processing failures, improving business processing efficiency, and solving the technical problem that the existing container command execution method needs to log in to the container and easily causes resource imbalance in the Pod. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;
[0036] Figure 2 It is a flowchart of a first embodiment of a command execution method for a container of the present invention;
[0037] Figure 3 Schematic diagram of the processing flow of the container of the present invention.
[0038] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0039] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0040] like Figure 1 As shown, Figure 1It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.
[0041] The command execution device of the container in the embodiment of the present invention may be a PC or a server device, on which a Java virtual machine runs.
[0042] like Figure 1 As shown, the command execution device of the container may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0043] Those skilled in the art will understand that Figure 1 The device structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0044] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a command execution program of the container.
[0045] exist Figure 1 In the device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the command execution program of the container stored in the memory 1005, and execute the operations in the command execution method of the container described below.
[0046] Based on the above hardware structure, an embodiment of a command execution method for a container of the present invention is proposed.
[0047] Reference Figure 2 , Figure 2 The flowchart of the first embodiment of the command execution method of the container of the present invention is shown in FIG. 1 . The command execution method of the container includes:
[0048] Step S10, when a container command to be executed corresponding to the target container is detected, intercepting the container command to be executed;
[0049] The containers in the Pod have a common operating environment, shared memory, and CPU resources. The resources in the Pod are limited. For example, the CPU allocated to the Pod is 2 cores and the memory is 4G. When executing the container command, you need to log in to the container through / bin / bash to operate. With the real environment of the actual container, you can execute any command. However, the executed command is easy to squeeze the resources of the Pod. When the container limit is reached, it is easy to be killed by K8s, which in turn affects the business container. For example, opening a large file can easily cause the memory to be exhausted, or executing a CPU-intensive operation, causing the CPU to soar. Therefore, the current container command execution method needs to log in to the container directly and operate in the real environment of the container, which is easy to cause resource imbalance in the Pod, such as occupying all memory resources or CPU resources in the Pod, thereby affecting the business container and causing business processing failure. In order to solve the above problem, this embodiment intercepts the container command to be executed sent to the container, and converts the container to be executed into a target container instruction that can be recognized by the target container according to the protocol conversion, and then sends the recognizable target container instruction to the target container, so that the target container performs the corresponding operation. There is no need to log in to the container, and there is no need to occupy container resources, thereby avoiding the failure of business processing caused by the execution of commands to seize business container resources, and improving business processing efficiency. Specifically, the command execution method of the container is applied to the command execution terminal, which can be a terminal including the target container, that is, the command execution terminal is outside the target container and intercepts the container command; it can also be a terminal that does not include the target container, that is, in another terminal where the non-target container is located, intercepting the container command, such as a command line terminal tool terminal (Terminal), which is used to input information to the host and output information to the outside. In this embodiment, Terminal is used as an example for explanation. When the Terminal detects a container command, it intercepts the current container command to be executed and the target container to be operated.
[0050] Step S20, converting the to-be-executed container command into a target container instruction recognizable by the target container based on the first data transmission protocol;
[0051] In this embodiment, Figure 3 As shown, in order to prevent users from directly operating the container and solve the problem that the protocol applicable to the Terminal is incompatible with the protocol applicable in the container, it is necessary to add a proxy (i.e., a proxy layer) for command format conversion. Specifically, a proxy layer is added to the terminal, and the container command to be executed is converted into a target container instruction recognizable by the target container through the first data transmission protocol provided in the proxy layer, i.e., the SPDY protocol.
[0052] Take ls / data / app as an example:
[0053] When the user enters ls / data / app in the input device:
[0054] Terminal inputs the data to be sent: {"type":"input","data":"ls / data / app"};
[0055] After receiving the data sent by the terminal, the proxy layer parses the command:
[0056] ls / data / app, then encapsulates the command into the data format of the SPDY protocol and sends the encapsulated container command to be executed to the container for execution.
[0057] The command execution method of the container further includes:
[0058] When a setting instruction is received, a target execution instruction in the setting instruction is obtained, and the target execution instruction that passes the execution instruction syntax check is added to a preset instruction whitelist to set the target execution instruction as a legal instruction.
[0059] In this embodiment, legal instructions can be configured in the terminal database by means of a whitelist. For example, ls and grep can be added to the whitelist. Then, during the parsing process, a verification success instruction is returned for the execution command in the whitelist, and a verification failure instruction is returned for the instruction command not in the whitelist, indicating that the parsing failed.
[0060] Wherein, after the step of intercepting the container command to be executed when the container command to be executed corresponding to the target container is detected, the method further includes:
[0061] Parsing the container command to be executed, and determining whether the parsed container command to be executed is a command set according to a command keyword, wherein the command set is a set of multiple sub-commands including two or more;
[0062] If the parsed container command to be executed is not a command set, performing a validity check on the container command to be executed;
[0063] When the container command to be executed fails to pass the legality check, a reminder message indicating that the current command is illegal is generated and displayed, so as to remind the user that the container command to be executed is an illegal container command.
[0064] When the container command to be executed passes the legality check, the following step is executed: step S20.
[0065] In this embodiment, in order to improve the user experience, the execution terminal can identify a command set composed of multiple subcommands. Specifically, various types of command fields are pre-stored, and then when it is detected that the container command to be executed is a set of multiple subcommands, the intercepted container command to be executed is parsed into execution command words and parameters according to the segmentation statement tokens. The command line is divided into symbols separated by a fixed metacharacter set: SPACE, TAB, NEWLINE, ;, (,), <, >, | or &, etc. The symbol type includes words, command keywords, I / O redirection symbols and semicolons, thereby obtaining a set corresponding to the subcommand. According to the command keyword, it is determined whether the set corresponding to the subcommand (that is, the parsed container command set to be executed) is a set of multiple subcommands including two or more. If so, each subcommand in the subcommand set is sequentially subjected to the steps of cyclic verification, conversion and sending, thereby avoiding the problem of poor user experience or reduced container execution efficiency caused by the user being able to enter only a single subcommand. If not, it means that the subcommand is a single command, and the legitimacy of the container command to be executed is verified according to the preset command whitelist or legal data table. When the container command to be executed fails to pass the legality check, a reminder message indicating that the current command is illegal is generated and displayed, so as to remind the user that the container command to be executed is an illegal container command.
[0066] Take ls-al / data|grep demo.txt as an example. This command is used to obtain detailed information about the demo.txt file in the / data directory. The specific parsing steps are as follows:
[0067] a) Split the command ls -al / data | grep demo.txt into two sub-commands ls -al / data and grep demo.txt;
[0068] b) Perform legal line verification on the split commands, that is, verify whether ls and grep are legal commands;
[0069] c) Further parameter parsing is performed on the command containing subcommands. According to ls-al / data, the ls command part is removed to obtain the two parameters -al / data. After removing grep, the parameter of the second command is demo.txt.
[0070] d) Perform a cyclic validity check on each of the parsed sub-commands.
[0071] Step S30: Send the target container instruction to the target container so that the target container executes the operation corresponding to the to-be-executed container command.
[0072] In this embodiment, the converted target container instruction that can be recognized by the target container is sent to the target container so that the target container executes the operation corresponding to the container command to be executed. At present, the exec command line provided by kubectl needs to clearly define the namespace to which the Pod currently operated belongs, the directory where the config configuration file is located, whether it is interactive, and other contents. However, ordinary users may not know the cluster to which the container belongs, the namespace, and other contents. Therefore, the container command execution method of this embodiment can reduce the difficulty of container operation for users and improve user experience.
[0073] This embodiment provides a method for executing commands for a container, by intercepting the container command to be executed when a container command to be executed corresponding to a target container is detected; converting the container command to be executed into a target container instruction recognizable by the target container based on a first data transmission protocol; and sending the target container instruction to the target container so that the target container executes the operation corresponding to the container command to be executed. In the above manner, the present invention intercepts the container command to be executed sent to the container, and converts the container to be executed into a target container instruction recognizable by the target container according to the protocol conversion, and then sends the recognizable target container instruction to the target container so that the target container executes the corresponding operation. There is no need to log in to the container, and there is no need to occupy container resources, thereby avoiding the execution of commands to occupy business container resources and causing business processing failures, improving business processing efficiency, and solving the technical problem that the existing container command execution method needs to log in to the container and easily causes resource imbalance in the Pod.
[0074] Furthermore, based on the first embodiment of the command execution method for a container of the present invention, a second embodiment of the command execution method for a container of the present invention is proposed.
[0075] In this embodiment, after step S10, the following steps are further included:
[0076] Based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory, a simulated context environment corresponding to the container command to be executed is generated outside the target container, so as to receive and recognize user input instructions or display the execution result of the container command based on the simulated context environment.
[0077] The step of generating a simulated context environment corresponding to the container command to be executed outside the target container based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory specifically includes:
[0078] Convert the to-be-executed container command into a container-recognizable command based on the custom abbreviated command, and determine a target working directory for the operation corresponding to the command to be executed on behalf of the container based on the recognizable command;
[0079] Determine whether the target working directory exists in the target container;
[0080] If the target working directory exists in the target container, obtaining the target file corresponding to the target working directory;
[0081] Based on the target environment variable and the target file, a simulation context environment including the target file is generated outside the target container.
[0082] In this embodiment, by executing the intercepted container command in the terminal, instead of executing the command in the ssh environment of the container, in order to facilitate the user to understand the command execution result or to facilitate interaction with the user, it is necessary to simulate the context environment of the matching container ssh in the terminal. Among them, the simulated context environment includes directory switching, current environment variable setting, and current working directory maintenance, etc. Specifically, in order to improve the efficiency of container execution, pre-customize the abbreviated command so that when the abbreviated command input by the user is detected, the command is replaced according to the pre-customized abbreviated command, such as alias ll, where alias II is used to display the document details (including permissions, belonging users and groups, size, time, name, etc.) under the current directory, which is the abbreviation of Is-I, equivalent to the shortcut of windows. There is no alias II in the standard linux command, so alias II is directly sent to the container and cannot be recognized and executed. In order to avoid the above problems, by pre-customizing the abbreviated command in the virtual ssh client, that is, saving the user-defined command abbreviation, it is convenient to improve the efficiency of container execution and improve the user experience. In a specific embodiment, the container command can be intercepted in advance, the abbreviated command can be converted into a corresponding recognizable container command through Windows, and the recognizable container command can be sent to the container for execution. Take the container instruction of switching directories as an example: assuming that the current directory is / home / test, and the command input is cd:cd / data / app, the execution result of this command is to switch the user's workspace from / home / test to / data / app directory.
[0083] Since the terminal cannot directly determine whether / data / app exists in the target container, it is necessary to execute ls / data / app in the container, that is, to determine whether the directory exists in the target container; if it does not exist, a relevant error will be prompted; if the / data / app directory exists in the target container, all files in the / data / app directory will be returned, that is, the page content that is the same as the target working directory of the target container will be displayed through the current interface of the terminal, so as to display the execution process and execution results of the container command, or receive the next interactive instruction input by the user based on the simulated context environment. If there are two directories in the target container, the switch is successful, that is, the current workspace is switched to / data / app in the terminal and the target container. If the switch fails, a relevant error will be prompted and the command execution ends.
[0084] Furthermore, after step S30, the method further includes:
[0085] Upon receiving a result instruction fed back by the target container based on the command of the container to be executed, converting the result instruction into a target terminal instruction recognizable by the simulation context environment based on a second data transmission protocol;
[0086] The target terminal command is displayed through the simulated context environment so that the user can understand the operation result corresponding to the target container executing the to-be-executed container command.
[0087] In this embodiment, in order to improve the user experience, after the target container executes the operation corresponding to the container command to be executed, the execution result can be returned to the terminal. Since the protocol applicable in the container is not compatible with the protocol applicable to the Terminal, it is necessary to add a proxy layer Proxy for command format conversion. Specifically, based on the second data transmission protocol, that is, the protocol applicable to the terminal, the result instructions fed back by the container are converted into target terminal instructions that can be recognized by the simulated context environment. The target terminal instructions can also be displayed through the simulated context environment so that the user can understand the operation results corresponding to the target container executing the container command to be executed. Take the content entered by the user on the keyboard as: ls / data / app as an example:
[0088] a)Terminal input sends data: {"type":"input","data":"ls / data / app"};
[0089] b) After receiving the data sent by the terminal, Prox parses the command: ls / data / app, then encapsulates it into the spdy protocol and sends the converted command to the container for execution;
[0090] c) After executing, the container returns the result instruction to the Proxy;
[0091] d) Proxy converts the returned result command into the terminal protocol: {"type":"output","data":"test.txt"};
[0092] e) After receiving the feedback result command data, Terminal parses the protocol and displays the parsed data on the display, thus completing the sending of a command and the return of the result. That is:
[0093] Input: ls / data / app and output: test.txt.
[0094] In a specific embodiment, take the command auto-completion instruction as an example:
[0095] In a Linux system container, users can enter the first few characters of the file to be searched in the container and perform a fuzzy search for the file by typing the tab key. This execution terminal will obtain the file name in the container that matches the relevant characters and automatically complete the full name of the matching file name. If there are multiple file names that match the relevant characters, all file names that match the relevant characters will be listed to facilitate user selection. For example:
[0096] When it is detected that the user types less lo, if there are loss and lost+found in the current container directory, then:
[0097] Intercept the currently input command "lo", search for all files and instructions beginning with "lo", and display loss and lost+found files for users to select;
[0098] In more embodiments, take the file editing operation instruction as an example:
[0099] Currently, in Linux systems, you can edit file contents through commands such as vi / vim. To avoid directly opening files in the container and squeezing container resources, you can use the following process:
[0100] a. Determine whether the file to be searched exists in the target container. If not, display the edit error instruction;
[0101] b. If the file to be found exists, it is further determined whether the size of the file to be found exceeds the preset file size, such as 100m. If the file to be found exceeds the preset file size, an edit error instruction is displayed;
[0102] c. If the file to be found does not exceed the preset file size, the file to be found is downloaded to a temporary directory of the current terminal.
[0103] d. Call the local vi command to perform editing operations on the files to be found in the temporary directory;
[0104] e. Detect whether the file to be found in the temporary directory has changed. If the file to be found in the temporary directory has changed, upload the changed file to be found in the temporary directory to the target container to replace the original file to be found in the container;
[0105] f. Delete the files to be found in the temporary directory.
[0106] In more embodiments, take the top execution instruction as an example:
[0107] In the Linux environment, top is used to view the process information of the current system, including CPU, memory, etc. This command can be exited by typing q, or filtered by typing f. Among them, the commands that need to operate according to the user's input are called interactive commands. The interactive command execution process is as follows:
[0108] 1. The execution terminal sends the user input command to the remote container;
[0109] 2. The execution terminal binds the local standard input, standard output, and standard error to the input and output streams of the proxy layer;
[0110] 3. Bind the input and output streams of the proxy layer to the standard input, standard output, and standard error of the container.
[0111] The present invention also provides a container command execution device, the container command execution device comprising:
[0112] A container command interception module, configured to intercept the container command to be executed when a container command to be executed corresponding to a target container is detected;
[0113] An input command conversion module, configured to convert the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol;
[0114] The container command execution module is used to send the target container instruction to the target container so that the target container executes the operation corresponding to the container command to be executed.
[0115] Furthermore, the command execution device of the container also includes:
[0116] The container environment simulation module is used to generate a simulation context environment corresponding to the container command to be executed outside the target container based on the target environment variables and the target working directory of the container command to be executed in the target container, so as to receive user input instructions or display the execution result of the container command based on the simulation context environment.
[0117] Furthermore, the command execution device of the container also includes:
[0118] a terminal instruction conversion module, configured to, upon receiving a result instruction fed back by the target container based on the to-be-executed container command, convert the result instruction into a target terminal instruction recognizable by the simulation context environment based on a second data transmission protocol;
[0119] The execution result display module is used to display the target terminal command through the simulated context environment so that the user can understand the operation result corresponding to the target container executing the to-be-executed container command.
[0120] Furthermore, the container environment simulation module specifically includes:
[0121] A directory determination unit, used for determining whether the target working directory exists in the target container;
[0122] A file acquisition unit, configured to acquire a target file corresponding to the target working directory if the target working directory exists in the target container;
[0123] The environment simulation unit is used to generate a simulation context environment including the target file outside the target container based on the target environment variable and the target file.
[0124] Furthermore, the command execution device of the container also includes:
[0125] A command parsing module, used to parse the container command to be executed, and determine whether the parsed container command to be executed is a command set according to a command keyword, wherein the command set is a set of multiple sub-commands including two or more;
[0126] A legality verification module, used for performing a legality verification on the container command to be executed if the parsed container command to be executed is not a command set;
[0127] Furthermore, the command execution device of the container also includes:
[0128] The illegal reminder module is used to generate and display a reminder message that the current command is illegal when the container command to be executed fails to pass the legality check, so as to remind the user that the container command to be executed is an illegal container command.
[0129] Furthermore, the legality verification module is also used for:
[0130] When the to-be-executed container command passes the legality check, the step of converting the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol is executed.
[0131] Furthermore, the command execution device of the container also includes:
[0132] When a setting instruction is received, a target execution instruction in the setting instruction is obtained, and the target execution instruction that passes the execution instruction syntax check is added to a preset instruction whitelist to set the target execution instruction as a legal instruction.
[0133] The methods executed by the above-mentioned program modules can refer to the various embodiments of the command execution method of the container of the present invention, and will not be described in detail here.
[0134] The present invention also provides a computer-readable storage medium.
[0135] The computer-readable storage medium of the present invention stores a command execution program for a container, and when the command execution program for a container is executed by a processor, the steps of the command execution method for a container as described above are implemented.
[0136] Among them, the method implemented when the command execution program of the container running on the processor is executed can refer to the various embodiments of the command execution method of the container of the present invention, which will not be repeated here.
[0137] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0138] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0139] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0140] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A container command execution method, characterized in that: The command execution method of the container comprises the following steps: When a container command to be executed corresponding to the target container is detected, intercepting the container command to be executed; Based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory, a simulated context environment corresponding to the container command to be executed is generated outside the target container, so as to receive and recognize the user input instruction or display the execution result of the container command based on the simulated context environment; Converting the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol; The target container instruction is sent to the target container so that the target container executes the operation corresponding to the to-be-executed container command.
2. The container command execution method according to claim 1, characterized in that: After the step of sending the target container instruction to the target container so that the target container executes the operation corresponding to the to-be-executed container command, the method further includes: Upon receiving a result instruction fed back by the target container based on the command of the container to be executed, converting the result instruction into a target terminal instruction recognizable by the simulation context environment based on a second data transmission protocol; The target terminal command is displayed through the simulated context environment so that the user can understand the operation result corresponding to the target container executing the to-be-executed container command.
3. The container command execution method according to claim 1, characterized in that: The step of generating a simulated context environment corresponding to the container command to be executed outside the target container based on the pre-stored custom abbreviated command, the target environment variable of the container command to be executed in the target container, and the target working directory specifically includes: Convert the to-be-executed container command into a container-recognizable command based on the custom abbreviated command, and determine a target working directory for the operation corresponding to the to-be-executed container command based on the recognizable command; Determine whether the target working directory exists in the target container; If the target working directory exists in the target container, obtaining the target file corresponding to the target working directory; Based on the target environment variable and the target file, a simulation context environment including the target file is generated outside the target container.
4. The container command execution method according to claim 1, characterized in that: After the step of intercepting the container command to be executed when the container command to be executed corresponding to the target container is detected, the method further includes: Parsing the container command to be executed, and determining whether the parsed container command to be executed is a command set according to a command keyword, wherein the command set is a set of multiple sub-commands including two or more; If the parsed container command to be executed is not a command set, performing a validity check on the container command to be executed; When the to-be-executed container command passes the legality check, the step of converting the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol is executed.
5. The container command execution method according to claim 4, characterized in that: After the step of performing a validity check on the container command to be executed if the parsed container command to be executed is not a command set, the method further includes: When the container command to be executed fails to pass the legality check, a reminder message indicating that the current command is illegal is generated and displayed, so as to remind the user that the container command to be executed is an illegal container command.
6. The command execution method of a container according to any one of claims 1 to 5, characterized in that: The command execution method of the container also includes: When a setting instruction is received, a target execution instruction in the setting instruction is obtained, and the target execution instruction that passes the execution instruction syntax check is added to a preset instruction whitelist to set the target execution instruction as a legal instruction.
7. A command execution device for a container, characterized in that: The command execution device of the container includes: A container command interception module, configured to intercept a container command to be executed when a container command to be executed corresponding to a target container is detected; a container environment simulation module, configured to generate a simulation context environment corresponding to the container command to be executed outside the target container based on a pre-stored custom abbreviated command, a target environment variable of the container command to be executed in the target container, and a target working directory, so as to receive and recognize a user input instruction or display an execution result of the container command based on the simulation context environment; An input command conversion module, configured to convert the to-be-executed container command into a target container instruction recognizable by the target container based on a first data transmission protocol; The container command execution module is used to send the target container instruction to the target container so that the target container executes the operation corresponding to the container command to be executed.
8. A command execution device for a container, characterized in that: The command execution device of the container includes: a memory, a processor, and a command execution program of the container stored in the memory and executable on the processor. When the command execution program of the container is executed by the processor, the steps of the command execution method of the container according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a command execution program for a container, and when the command execution program for a container is executed by a processor, the steps of the command execution method for a container according to any one of claims 1 to 6 are implemented.
