All Products
Search
Document Center

Use Alibaba Cloud CLI to manage ECI

Last Updated: Aug 13, 2019

Cloud Shell of Alibaba Cloud is a free O&M support product that is pre-installed with Alibaba Cloud CLI. You can click the following link to open the tutorial and quickly learn about common operations for Elastic Container Instance (ECI).

Open Cloud Shell

You can perform the following steps in Cloud Shell. Click the preceding link to experience ECI operations in Cloud Shell.

Use Alibaba Cloud CLI to manage ECI resources

Prerequisites

  • You have VPCs in the current region and VSwitches in the zone in which the container group resides.
  • Security groups are available in the current region.
  1. aliyun vpc DescribeVSwitches | jq .VSwitches.VSwitch | jq .[] | jq .ZoneId

If no data is returned for the preceding command, no VPCs are available in the region. In this case, you must create required VPCs in the VPC console. If none of the VSwitches are in the zone and region in which the container group resides, create VSwitches.

If VSwitches are returned, select the VSwitches in the zone and region in which the container group resides. You can run the following command to query the VSwitch IDs for future use. Assume that the first returned VSwitch is in the zone and region in which the container group resides:

  1. VSwitchId=`aliyun vpc DescribeVSwitches | jq .VSwitches.VSwitch | jq .[0] | jq -r .VSwitchId`

Similarly, run the following command to check whether security groups are available in the region.

  1. aliyun ecs DescribeSecurityGroups | jq .SecurityGroups.SecurityGroup | jq .[] | jq .SecurityGroupId

If no security group is available, create security groups in the security group console.

If security groups are available, query the security group IDs for future use.

  1. SecurityGroupId=`aliyun ecs DescribeSecurityGroups | jq .SecurityGroups.SecurityGroup | jq .[0] | jq -r .SecurityGroupId`

Learn to use Alibaba Cloud ECI CLI

Query available API operations.

  1. aliyun eci help

Alibaba Cloud CLI supports the following API operations:

List of available API operations:

  • CreateContainerGroup
  • DeleteContainerGroup
  • DescribeContainerGroups
  • DescribeContainerLog

CreateContainerGroup

View available options.

  1. aliyun eci CreateContainerGroup help

SecurityGroupId and VSwitchId are required parameters.

Create a container group.

  1. aliyun eci CreateContainerGroup --SecurityGroupId ${SecurityGroupId} --VSwitchId ${VSwitchId} --ContainerGroupName test-eci --Container.1.Image nginx --Container.1.Name nginx --Container.1.Cpu 1 --Container.1.Memory 2

After the container group is created, a message similar to the following is returned.

{“ContainerGroupId”:”eci-bp19vpbluci6jm3wblj2”,”RequestId”:”F1F69DA4-4952-441D-A164-7C8E3EDF0DC0”}

Note the value of ContainerGroupId, which will be used in the DescribeContainerLog operation.

DescribeContainerGroups

View available options.

  1. aliyun eci DescribeContainerGroups help

Query available container groups in the current region.

  1. aliyun eci DescribeContainerGroups --ContainerGroupName test-eci | jq

DescribeContainerLog

View available options.

  1. aliyun eci DescribeContainerLog help

View the internal logs of the NGINX containers in the container group that you have created.

  1. ContainerGroupId=`aliyun eci DescribeContainerGroups --ContainerGroupName test-eci | jq .ContainerGroups | jq .[] | jq -r .ContainerGroupId`
  2. aliyun eci DescribeContainerLog --ContainerGroupId ${ContainerGroupId} --ContainerName nginx

DeleteContainerGroup

View available options.

  1. aliyun eci DeleteContainerGroup help

Delete the container group that you have created.

  1. aliyun eci DeleteContainerGroup --ContainerGroupId ${ContainerGroupId}

Tutorial learning completed

Congratulations! You have completed learning the tutorial on how to use Alibaba Cloud ECI CLI.