All Products
Search
Document Center

Elastic Container Instance:Obtain the metadata from a container

Last Updated:Oct 19, 2022

This topic describes how to obtain the metadata of an elastic container instance from a container to present the metadata to running containers.

Method 1: Use MetaServer to access metadata

You can perform the following operations to obtain the metadata of an elastic container instance:

  1. Connect to a container. For more information, see Connect to an elastic container instance.

  2. Run the following command to access the root directory of the metadata:

    curl http://100.100.100.200/latest/meta-data/
  3. Append the name of a metadata item to the command to obtain the information about the item.

    For example, run the following command to obtain the ID of the elastic container instance:

    curl http://100.100.100.200/latest/meta-data/instance-id

    The following table describes the metadata items that you can obtain for an elastic container instance.

    Metadata item

    Description

    /dns-conf/nameservers

    The Domain Name System (DNS) configurations of the elastic container instance.

    /eipv4

    The elastic IPv4 address of the elastic container instance.

    /hostname

    The hostname of the elastic container instance, which is the ContainerGroupName value.

    /instance-id

    The ID of the elastic container instance.

    /mac

    The media access control (MAC) address of the elastic container instance.

    /network/interfaces/

    The MAC addresses of the network interface controllers (NICs).

    /network/interfaces/macs/[mac]/network-interface-id

    The ID of the NIC. Replace [mac] with the MAC address of the elastic container instance.

    /network/interfaces/macs/[mac]/netmask

    The subnet mask of the NIC.

    /network/interfaces/macs/[mac]/vswitch-cidr-block

    The IPv4 CIDR block of the vSwitch to which the NIC belongs.

    /network/interfaces/macs/[mac]/vpc-cidr-block

    The IPv4 CIDR block of the virtual private cloud (VPC) to which the NIC belongs.

    /network/interfaces/macs/[mac]/private-ipv4s

    The private IPv4 addresses assigned to the NIC.

    /network/interfaces/macs/[mac]/vpc-ipv6-cidr-blocks

    The IPv6 CIDR block of the VPC to which the NIC belongs. This item is applicable only to the elastic container instances that reside within VPCs and are assigned IPv6 addresses.

    /network/interfaces/macs/[mac]/vswitch-id

    The ID of a vSwitch in the VPC to which the security group of the NIC belongs.

    /network/interfaces/macs/[mac]/vpc-id

    The ID of the VPC to which the security group of the NIC belongs.

    /network/interfaces/macs/[mac]/primary-ip-address

    The primary private IP address of the NIC.

    /network/interfaces/macs/[mac]/gateway

    The IPv4 gateway address of the VPC to which the NIC belongs.

    /instance/max-netbw-egress

    The maximum outbound internal bandwidth of the elastic container instance. Unit: Kbit/s.

    /instance/max-netbw-ingerss

    The maximum inbound internal bandwidth of the elastic container instance. Unit: Kbit/s.

    /network/interfaces/macs/[mac]/ipv6s

    The IPv6 addresses assigned to the NIC. This item is applicable only to the elastic container instances that reside within VPCs and are assigned IPv6 addresses.

    /network/interfaces/macs/[mac]/ipv6-gateway

    The IPv6 gateway address of the VPC to which the NIC belongs.

    /network/interfaces/macs/[mac]/vswitch-ipv6-cidr-block

    The IPv6 CIDR block of the vSwitch to which the NIC is connected. This item is applicable only to the elastic container instances that reside within VPCs and are assigned IPv6 addresses.

    /private-ipv4

    The private IPv4 address of the elastic container instance.

    /ntp-conf/ntp-servers

    The address of the Network Time Protocol (NTP) server.

    /owner-account-id

    The ID of the Alibaba Cloud account to which the elastic container instance belongs.

    /region-id

    The region ID of the elastic container instance.

    /serial-number

    The serial number of the elastic container instance.

    /vpc-id

    The ID of the VPC to which the elastic container instance belongs.

    /vpc-cidr-block

    The CIDR block of the VPC to which the elastic container instance belongs.

    /vswitch-cidr-block

    The CIDR block of the vSwitch to which the elastic container instance is connected.

    /vswitch-id

    The ID of the vSwitch to which the elastic container instance is connected.

    /zone-id

    The zone ID of the elastic container instance.

    /ram/security-credentials/[role-name]

    The temporary Security Token Service (STS) credentials generated for the Resource Access Management (RAM) role of the elastic container instance. You can obtain the STS credentials only after you specify a RAM role to an elastic container instance. Replace [role-name] with the name of the RAM role. If [role-name] is not specified, the name of the RAM role is returned.

Method 2: Configure environment variables for a container

You can obtain the information about an elastic container instance by configuring environment variables for a container in the instance. The metadata items of an elastic container instance that can be obtained in this manner include the instance ID, instance name, region ID of the instance, zone ID of the instance, and container name.

Key

Value

Description

eci_id

__ECI_ID__

The ID of the elastic container instance.

eci_name

__ECI_NAME__

The name of the elastic container instance.

region_id

__REGION_ID__

The region ID of the elastic container instance.

zone_id

__ZONE_ID__

The zone ID of the elastic container instance.

container_name

__CONTAINER_NAME__

The name of the container in the elastic container instance.

params = {
        'Container.1.Image': 'registry-vpc.cn-shanghai.aliyuncs.com/eci_open/nginx:alpine',
        'Container.1.Name': 'nginx',
        'SecurityGroupId': 'sg-uf6biempwqvodk7a****',
        'VSwitchId': 'vsw-uf6mhqg2wiq9iifhn****',
        'ContainerGroupName': 'test-env',
        # Configure environment variables.
        'Container.1.EnvironmentVar.1.Key': 'eci_id',
        'Container.1.EnvironmentVar.2.Key': 'eci_name',
        'Container.1.EnvironmentVar.3.Key': 'region_id',
        'Container.1.EnvironmentVar.4.Key': 'zone_id',
        'Container.1.EnvironmentVar.5.Key': 'container_name',
        'Container.1.EnvironmentVar.1.Value': '__ECI_ID__',
        'Container.1.EnvironmentVar.2.Value': '__ECI_NAME__',
        'Container.1.EnvironmentVar.3.Value': '__REGION_ID__',
        'Container.1.EnvironmentVar.4.Value': '__ZONE_ID__',
        'Container.1.EnvironmentVar.5.Value': '__CONTAINER_NAME__',
    }

You can log on to the Elastic Container Instance console and connect to the container to check whether the configured environment variables have taken effect. For more information, see Connect to an elastic container instance. view