All Products
Search
Document Center

Elastic Container Instance:Obtain metadata from a container

Last Updated:Apr 01, 2026

Applications running inside an elastic container instance (ECI) often need runtime information — such as the instance ID, region, or network configuration — without hardcoding environment-specific values. ECI exposes this information as instance metadata, which your containers can query or consume at startup.

Two methods are available:

  • MetaServer — query any metadata item on demand over HTTP from inside a container. Provides the full set of metadata fields.

  • Environment variables — inject a fixed subset of instance information into containers at creation time, so applications read it like any other environment variable, with no HTTP call required.

Method 1: Use MetaServer to query metadata

MetaServer is an HTTP service accessible at http://100.100.100.200 from inside a container running on an ECI instance.

Query a metadata item

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

  2. Run the following command, replacing <metadata> with the path of the item you want:

    curl http://100.100.100.200/latest/meta-data/<metadata>

    For example, to get the instance ID:

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

If curl is not installed in the container, install it before running the command.

Available metadata items

For paths that include [mac], replace it with the Media Access Control (MAC) address of the ECI instance (available at /mac). For the path that includes [role-name], replace it with the name of the Resource Access Management (RAM) role.

Metadata itemDescription
/dns-conf/nameserversThe Domain Name System (DNS) configurations of the ECI instance.
/eipv4The elastic IPv4 address of the ECI instance.
/hostnameThe hostname of the ECI instance. This is the ContainerGroupName value.
/instance-idThe ID of the ECI instance.
/macThe MAC address of the ECI instance.
/network/interfaces/The MAC addresses of the network interface controllers (NICs).
/network/interfaces/macs/[mac]/network-interface-idThe ID of the NIC.
/network/interfaces/macs/[mac]/netmaskThe subnet mask of the NIC.
/network/interfaces/macs/[mac]/vswitch-cidr-blockThe IPv4 CIDR block of the vSwitch to which the NIC is connected.
/network/interfaces/macs/[mac]/vpc-cidr-blockThe IPv4 CIDR block of the virtual private cloud (VPC) to which the NIC belongs.
/network/interfaces/macs/[mac]/private-ipv4sThe private IPv4 addresses assigned to the NIC.
/network/interfaces/macs/[mac]/vpc-ipv6-cidr-blocksThe IPv6 CIDR block of the VPC to which the NIC belongs. Applicable only to ECI instances that reside in VPCs and have IPv6 addresses assigned.
/network/interfaces/macs/[mac]/vswitch-idThe ID of the vSwitch that resides in the same VPC as the security group of the NIC.
/network/interfaces/macs/[mac]/vpc-idThe ID of the VPC in which the security group of the NIC resides.
/network/interfaces/macs/[mac]/primary-ip-addressThe primary private IP address of the NIC.
/network/interfaces/macs/[mac]/gatewayThe IPv4 gateway address of the NIC.
/instance/max-netbw-egressThe maximum outbound internal bandwidth of the ECI instance. Unit: Kbit/s.
/instance/max-netbw-ingerssThe maximum inbound internal bandwidth of the ECI instance. Unit: Kbit/s.
/network/interfaces/macs/[mac]/ipv6sThe IPv6 addresses assigned to the NIC. Applicable only to ECI instances that reside in VPCs and have IPv6 addresses assigned.
/network/interfaces/macs/[mac]/ipv6-gatewayThe IPv6 gateway address of the VPC to which the NIC belongs.
/network/interfaces/macs/[mac]/vswitch-ipv6-cidr-blockThe IPv6 CIDR block of the vSwitch to which the NIC is connected. Applicable only to ECI instances that reside in VPCs and have IPv6 addresses assigned.
/private-ipv4The private IPv4 address of the ECI instance.
/ntp-conf/ntp-serversThe address of the Network Time Protocol (NTP) server.
/owner-account-idThe ID of the Alibaba Cloud account to which the ECI instance belongs.
/region-idThe region ID of the ECI instance.
/serial-numberThe serial number of the ECI instance.
/vpc-idThe ID of the VPC in which the ECI instance resides.
/vpc-cidr-blockThe CIDR block of the VPC in which the ECI instance resides.
/vswitch-cidr-blockThe CIDR block of the vSwitch to which the ECI instance is connected.
/vswitch-idThe ID of the vSwitch to which the ECI instance is connected.
/zone-idThe zone ID of the ECI instance.
/ram/security-credentials/[role-name]The temporary Security Token Service (STS) credentials for the RAM role of the ECI instance. Available only after a RAM role is assigned to the instance. If you do not replace [role-name], the instance name is returned instead.

Method 2: Inject metadata as environment variables

This method injects a fixed subset of instance information into a container as environment variables at creation time. Applications read the values like any other environment variable — no HTTP call required.

This method supports five fields: instance ID, instance name, region ID, zone ID, and container name. For the full metadata set, use Method 1.

Supported environment variables

Set the following key-value pairs when creating the container. ECI automatically replaces the placeholder values with the actual instance information.

KeyValueDescription
eci_id__ECI_ID__The ID of the ECI instance.
eci_name__ECI_NAME__The name of the ECI instance.
region_id__REGION_ID__The region ID of the ECI instance.
zone_id__ZONE_ID__The zone ID of the ECI instance.
container_name__CONTAINER_NAME__The name of the container.

Configure via OpenAPI

Call the CreateContainerGroup operation and use the Container.N.EnvironmentVar.N.Key and Container.N.EnvironmentVar.N.Value parameters to set the environment variables:

ContainerGroupName=test-env
Container.1.Image=registry-vpc.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
Container.1.Name=container-1
# 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__

Configure via the console

  1. Open the Elastic Container Instance console and start creating an ECI instance.

  2. In the Container Configurations section, select a container, expand Advanced Settings, and turn on Environment Variable.

  3. Add the key-value pairs listed in the table above.

    元数据.png

  4. After the instance is created, connect to the container to verify that the environment variables took effect. For more information, see Connect to an elastic container instance.

    view