Commands can be run in containers on Linux Elastic Compute Service (ECS) instances. Conventionally, to run commands in containers on Linux instances, you need to connect to the instances and then access containers on the instances. Cloud Assistant helps simplify this process. 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. You can set the ContainerId
or ContainerName
parameter to the name or ID of a Kubernetes container when you call the RunCommand or InvokeCommand operation to run commands in the container.
Prerequisites
The instances are in the Running (Running) state.
Cloud Assistant Agent is installed on the instances and the version of Cloud Assistant Agent is 2.2.3.344 or later.
For more information, see Install Cloud Assistant Agent.
Limits
Cloud Assistant can be used to run commands only in containers that are managed by Kubernetes based on the Container Runtime Interface (CRI) and run within the Docker, containerd, or CRI-O container runtime.
The limits that are described in the following table are imposed by the CRI when you run commands in containers. The table also provides solutions to resolve the limits.
Limits
Description and countermeasure
You can use only the default user of a container to run commands in the container.
After you specify the
ContainerId
parameter, theContainerName
parameter, or both, theUsername
parameter does not take effect. The default user of the container is used to run the commands.If you want to change the user that is used to run the commands, run the
sudo
command in the container. Make sure that the container image supports user change.
You can run commands only in the default working directory of a container.
After you specify the
ContainerId
parameter, theContainerName
parameter, or both, theWorkingDir
parameter does not take effect. The commands are run in the default working directory of the container.If you want to change the working directory of the commands, add the
cd
command at the beginning of the shell script.
You can run only shell scripts in a container. You cannot add a command in a format similar to
#!/usr/bin/python
at the beginning of a script to specify a script interpreter.After you specify the
ContainerId
parameter, theContainerName
parameter, or both, Linux shell scripts are run by using/bin/sh
in the container. The script interpreter specified by the command that starts with#!
cannot be recognized.To run a script in another language in the container, call the interpreter of the language in the container and pass in the script. For example, you can add the
/usr/bin/python -c 'import sys; print(sys.version_info)'
command at the beginning of a script to call the Python interpreter in the container.
Procedure
View the ID and name of a Kubernetes container.
Use Cloud Assistant to run commands in containers.
You can run commands in specific containers only by calling API operations. When you call the RunCommand or InvokeCommand operation specific to Cloud Assistant to run a command in a specific container, you must specify the
ContainerId
parameter, theContainerName
parameter, or both.NoteFor information about limits on using Cloud Assistant to run commands, see the "Prerequisites" and "Background information" sections in the Use the immediate execution feature topic.
Result
You can call the DescribeInvocations or DescribeInvocationResults operation to query the execution status or execution results of commands. You can view the ContainerId
and ContainerName
values in the response.