All Products
Search
Document Center

Elastic Container Instance:Commit a container and push to Container Registry

Last Updated:Jun 21, 2026

After you create an Elastic Container Instance (ECI) instance, you can modify its containers. To save these modifications, you can commit a container to a new image and push that image to Container Registry. This topic describes how to do this by using the CommitContainer and DescribeCommitContainerTask API operations.

Prerequisites

  1. Create a Container Registry instance and an image repository, and get the repository address.

    To learn how to create a Container Registry instance and an image repository, see the following documents:

    After you create the repository, get its address from the image repository page. This topic uses a private network address.

    In the image repository list, click the operation button for the target repository to view three types of endpoint addresses: public endpoint (registry.cn-beijing.aliyuncs.com), VPC endpoint (registry-vpc.cn-beijing.aliyuncs.com), and Classic Network endpoint (registry-internal.cn-beijing.aliyuncs.com). The VPC and Classic Network endpoints are private network addresses.

  2. Create a RAM role, grant permissions to the role, and then get the ARN of the role.

    1. Create a RAM role.

      For more information, see Create a RAM role for a trusted Alibaba Cloud service. Note the following settings:

      • On the Select Role Type page, select Alibaba Cloud Service as the trusted entity.

      • On the Configure Role page, set Normal Service Role to Normal Service Role, enter a custom role name, and select ECI as the trusted service.

    2. Grant permissions to the RAM role.

      For more information, see Manage permissions for a RAM role. When you grant permissions, attach the AliyunContainerRegistryFullAccess policy.

    3. Get the ARN of the role.

      You can get the ARN from the Basic Information section on the role details page.

Parameters

Call the CommitContainer API operation to create an asynchronous task that saves a specified container in an ECI instance to an image and pushes the image to an image repository in Container Registry. The following table describes the main parameters of the CommitContainer API operation. For more information, see CommitContainer.

Parameter

Type

Example

Description

ContainerGroupId

string

eci-bp1do4xz75fa5sd****

The ID of the ECI instance that contains the container to commit.

ContainerName

string

container-1

The name of the container to commit.

Image.Repository

string

registry-vpc.cn-beijing.aliyuncs.com/test/test-****

The address of the Container Registry image repository.

For security reasons, you can only push images to Container Registry.

Image.Tag

string

1.0.1

The image tag.

AcrRegistryInfo.InstanceId

string

cri-nwj395hgf6f3****

The ID of the Container Registry Enterprise Edition instance.

Required for Enterprise Edition instances only.

AcrRegistryInfo.RegionId

string

cn-beijing

The region of the Container Registry Enterprise Edition instance.

Required for Enterprise Edition instances only.

Arn.RoleArn

string

acs:ram::1609982529******:role/commit-test

The ARN of the authorized RAM role. For information about how to configure and get the ARN, see the Prerequisites section.

Arn.RoleType

string

service

The authorization type. Set this to service to use a RAM role.

A successful call returns a TaskId. Use this ID with the DescribeCommitContainerTask API operation to query the task status. If TaskStatus is Succeeded, the image has been successfully generated and pushed to Container Registry. For more information about the parameters of the DescribeCommitContainerTask API operation, see DescribeCommitContainerTask.

Example

  1. Create an ECI instance A.

  2. Connect to ECI instance A and run commands in the container.

    For example, write a file named hello.txt into the container.

    Elastic Container Service!
    root@eci-a:/# ls
    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    root@eci-a:/# echo hello eci >> hello.txt
    root@eci-a:/# ls
    bin  boot  dev  etc  hello.txt  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    root@eci-a:/# cat hello.txt
    hello eci
    root@eci-a:/#
  3. Call the CommitContainer API operation to commit the container in instance A to an image and push the image to Container Registry.

    The following sample parameters are used:

    RegionId=cn-beijing
    ContainerGroupId=eci-2zeh3j8kdnqvnf5n****
    ContainerName=container-1
    Image.Repository=registry-vpc.cn-beijing.aliyuncs.com/***-test/***-registry
    Image.Tag=1.0.1
    Arn.RoleArn=acs:ram::1609982529******:role/commit-test
    Arn.RoleType=service

    For a Container Registry Enterprise Edition instance, you must also specify the instance ID and region by using the AcrRegistryInfo parameters. Example:

    AcrRegistryInfo.InstanceId=cri-nwj395hgf6f3****
    AcrRegistryInfo.RegionId=cn-beijing

    The following response is expected:

    {
      "TaskId": "t-2zej6nstkg744qc3****",
      "RequestId": "4ADE19FF-C487-5020-A6E4-03D5D9708834"
    }
  4. Call the DescribeCommitContainerTask API operation to check the task status.

    The following sample parameters are used:

    RegionId=cn-beijing
    TaskId=["t-2zej6nstkg744qc3****"]

    The following response is expected. A TaskStatus of Succeeded indicates that the task is successful. Within CommitPhaseInfos, the Success status for the PushCommittedImage phase confirms that the image has been pushed to the specified image repository.

    {
      "TotalCount": 1,
      "CommitTasks": [
        {
          "TaskId": "t-2zej6nstkg744qc3****",
          "ContainerName": "container-1",
          "CommitPhaseInfos": [
            ......
            {
              "Status": "Success",
              "RecordTime": "2023-02-01T11:08:04.313047785+08:00",
              "Phase": "PushCommittedImage",
              "Message": "Push image registry-vpc.cn-beijing.aliyuncs.com/***-test/***-registry:1.0.1 successfully"
            }
          ],
          "CreationTime": "2023-02-01T11:08:00Z",
          "TaskStatus": "Succeeded",
          "FinishedTime": "2023-02-01T11:08:10Z"
        }
      ],
      "NextToken": "",
      "RequestId": "42E65299-8224-5D4A-915E-5AEC04A523FC"
    }

    You can then log on to the Container Registry console and find the new image pushed by the ECI instance in the target image repository.

  5. Create ECI instance B from the new image.

    Use the image that the CommitContainer task pushed to Container Registry. For example, registry-vpc.cn-beijing.aliyuncs.com/***-test/***-registry:1.0.1.

    Note

    When you select the image, choose My Images for a Personal Edition repository, or Container Registry Enterprise Edition image for an Enterprise Edition repository.

  6. Verify that the container environment in instance B is consistent with that of instance A.

    In this example, the hello.txt file was added to the container of instance A. Because instance B is created from the image of instance A, its container already includes the hello.txt file.

    Elastic  Container Service!
    root@eci-b:/# ls
    bin  boot  dev  etc  hello.txt  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    root@eci-b:/# cat hello.txt
    hello eci
    root@eci-b:/#