Commands can be run in containers on Linux Elastic Compute Service (ECS) instances. Conventionally, to run commands in containers on Linux instances, you must first connect to the instances and then access containers on the instances. Cloud Assistant helps simplify this procedure. Specifically, you can use Cloud Assistant to directly connect to containers in a password-free, logon-free manner without the use of jump servers and run commands in the containers. When you call the RunCommand or InvokeCommand operation, you can set ContainerId
or ContainerName
to specify Kubernetes containers in which to run commands.
Prerequisites
- The instances are in the Running (Running) state.
- The Cloud Assistant Agent is installed on the instances and the version of the Cloud Assistant Agent is not earlier than 2.2.3.344.
For more information, see Install the .
Limits
- Cloud Assistant can be used to run commands only in containers that are managed by Kubernetes based on Container Runtime Interface (CRI) and run within a Docker, containerd, or CRI-O container runtime.
- Based on the CRI, the limits described in the following table apply when you run commands in containers.
Limits Description You can run a command in a container only as the default user of the container. - If you specify
ContainerId
,ContainerName
, or both, the specifiedUsername
parameter does not take effect. The command is run as the default user of the container. - If you want to switch to another user, you can run the
sudo
command in the container.
You can run a command only in the default working directory of a container. - If you specify
ContainerId
,ContainerName
, or both, the specifiedWorkingDir
parameter does not take effect. The command is run in the default working directory of the container. - If you want to switch the working directory of the command, you can add the
cd
command at the beginning of a shell script.
You can run only shell scripts in containers. You cannot add a command in a format similar to #!/usr/bin/python
at the beginning of a script to specify a script interpreter.- If you specify
ContainerId
,ContainerName
, or both, Linux shell scripts are run by using/bin/sh
in containers. The script interpreter specified by running the command that begins with#!
cannot be recognized. - To run scripts in other languages in containers, you can call the interpreter in the containers and pass in the script that you want to run. For example, you can add the
/usr/bin/python -c 'import sys; print(sys.version_info)'
command at the beginning of the script to call the Python interpreter in a container.
- If you specify
Procedure
- View the ID and name of a Kubernetes container.
- Use Cloud Assistant to run commands in containers. You can run commands in specified containers only by calling API operations. When you call the RunCommand or InvokeCommand operation specific to Cloud Assistant to run a command in a specified container, you must specify
ContainerId
,ContainerName
, or both parameters.Note For information about limits on using Cloud Assistant to run commands, see the "Prerequisites" and "Context" sections in Use the immediate execution feature.
Result
You can call the DescribeInvocations or DescribeInvocationResults operation to query the execution states or execution results of commands. You can view theContainerId
and ContainerName
values in the response.