Manage Elastic Container Instance (ECI) instances using Alibaba Cloud CLI

Updated at:

You can use the Alibaba Cloud CLI to call ECI APIs and manage your Elastic Container Instance (ECI) instances.

About this tutorial

The steps and examples in this tutorial are integrated into Alibaba Cloud Shell. You can open this tutorial in Cloud Shell to quickly manage your ECI instances using the Alibaba Cloud CLI. You can perform operations such as creating ECI container groups, retrieving information about ECI container groups, and deleting ECI container groups.

Prerequisites

Before you use the Alibaba Cloud CLI to call ECI APIs, ensure the following requirements are met:
  • You have activated the ECI service and have the required permissions to access the relevant cloud resources.
    Note ECI uses the AliyunECIContainerGroupRole role by default to access your resources in other cloud products.
  • You have a VPC network in a region where ECI is available, and a vSwitch in a zone where ECI is available.
  • You have a security group in a region where ECI is available.

Related APIs

You can use the Alibaba Cloud CLI to call the following APIs to manage ECI instances.
API Name Description
CreateContainerGroup Creates a container group.
DescribeContainerGroups Queries information about container groups in a batch.
DescribeContainerLog Queries the log information of a container group.
DeleteContainerGroup Deletes a container group.
ExecContainerCommand Executes a command in a container.
Note Run the aliyun eci help command to view the available methods for managing ECI instances with the Alibaba Cloud CLI.

Examples

Before you create an ECI instance, obtain the vSwitch ID and security group ID.

  1. Query the list of created vSwitches.
    aliyun vpc DescribeVSwitches | jq .VSwitches.VSwitch | jq .[] | jq .ZoneId
    Note If the command returns an empty output, no VPC network exists in the region. Log on to the VPC console to create a VPC. If none of the vSwitches are in a region and zone where ECI is available, you must also create a vSwitch.
  2. Assume that the first vSwitch meets the requirements. Run the following command to obtain the vSwitch ID.
    VSwitchId=`aliyun vpc DescribeVSwitches | jq .VSwitches.VSwitch | jq .[0] | jq -r .VSwitchId`
    Note Select a vSwitch that is in a zone where ECI is available within the current region.
  3. Query the basic information about created security groups.
    aliyun ecs DescribeSecurityGroups | jq .SecurityGroups.SecurityGroup | jq .[] | jq .SecurityGroupId
    Note If the command returns an empty output, log on to the Elastic Compute Service console to create a security group.
  4. Run the following command to obtain the security group ID.
    SecurityGroupId=`aliyun ecs DescribeSecurityGroups | jq .SecurityGroups.SecurityGroup | jq .[0] | jq -r .SecurityGroupId`
  5. Use the Alibaba Cloud CLI to manage ECI instances.
    The following examples show common operations:
    • Create a container group.
      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
      The output is similar to the following:
      {"ContainerGroupId":"eci-bp19vpbluci6jm3wblj2","RequestId":"F1F69DA4-4952-441D-A164-7C8E3EDF0DC0"}
    • Retrieve information about container groups in a batch.
      aliyun eci DescribeContainerGroups --ContainerGroupName test-eci | jq
    • Retrieve the log information of a container group.
      ContainerGroupId=`aliyun eci DescribeContainerGroups --ContainerGroupName test-eci | jq .ContainerGroups | jq .[] | jq -r .ContainerGroupId`
      aliyun eci DescribeContainerLog --ContainerGroupId ${ContainerGroupId} --ContainerName nginx
    • Delete a container group.
      aliyun eci DeleteContainerGroup --ContainerGroupId ${ContainerGroupId}