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
Connect to a container. For more information, see Connect to an elastic container instance.
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
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 item | Description |
|---|---|
/dns-conf/nameservers | The Domain Name System (DNS) configurations of the ECI instance. |
/eipv4 | The elastic IPv4 address of the ECI instance. |
/hostname | The hostname of the ECI instance. This is the ContainerGroupName value. |
/instance-id | The ID of the ECI instance. |
/mac | The MAC address of the ECI instance. |
/network/interfaces/ | The MAC addresses of the network interface controllers (NICs). |
/network/interfaces/macs/[mac]/network-interface-id | The ID of the NIC. |
/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 is connected. |
/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. Applicable only to ECI instances that reside in VPCs and have IPv6 addresses assigned. |
/network/interfaces/macs/[mac]/vswitch-id | The ID of the vSwitch that resides in the same VPC as the security group of the NIC. |
/network/interfaces/macs/[mac]/vpc-id | The ID of the VPC in which the security group of the NIC resides. |
/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 NIC. |
/instance/max-netbw-egress | The maximum outbound internal bandwidth of the ECI instance. Unit: Kbit/s. |
/instance/max-netbw-ingerss | The maximum inbound internal bandwidth of the ECI instance. Unit: Kbit/s. |
/network/interfaces/macs/[mac]/ipv6s | The 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-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. Applicable only to ECI instances that reside in VPCs and have IPv6 addresses assigned. |
/private-ipv4 | The private IPv4 address of the ECI 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 ECI instance belongs. |
/region-id | The region ID of the ECI instance. |
/serial-number | The serial number of the ECI instance. |
/vpc-id | The ID of the VPC in which the ECI instance resides. |
/vpc-cidr-block | The CIDR block of the VPC in which the ECI instance resides. |
/vswitch-cidr-block | The CIDR block of the vSwitch to which the ECI instance is connected. |
/vswitch-id | The ID of the vSwitch to which the ECI instance is connected. |
/zone-id | The 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.
| Key | Value | Description |
|---|---|---|
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
Open the Elastic Container Instance console and start creating an ECI instance.
In the Container Configurations section, select a container, expand Advanced Settings, and turn on Environment Variable.
Add the key-value pairs listed in the table above.

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.
