All Products
Search
Document Center

Manage an image cache

Last Updated: Dec 21, 2021

Image caches accelerate image pulling and reduce the startup time of elastic container instances. This topic describes how to create, query, update, and delete an image cache.

Create an image cache

You can manually create an image cache by using the Elastic Container Instance console or by calling an API operation in OpenAPI Explorer.

Note

The system can automatically create image caches. You can enable automatic match of image caches when you create an elastic container instance. Then, if no image cache is matched, the system automatically creates an image cache.

Create an image cache by calling an API operation

You can call the CreateImageCache API operation to create an image cache. The following table describes the parameters of the operation. For more information, see CreateImageCache.

Parameter

Type

Example

Description

RegionId

String

cn-hangzhou

The region ID of the image cache.

ImageCacheName

String

testcache

The name of the image cache.

Image.N

RepeatList

registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.15.10-perl

Container image N used to create the image cache.

SecurityGroupId

String

sg-uf66jeqopgqa9hdn****

The ID of the security group.

VSwitchId

String

vsw-uf6h3rbwbm90urjwa****

The ID of the vSwitch

ImageCacheSize

Integer

20

The size of the image cache. The default value is 20 GiB.

RetentionDays

Integer

7

The retention period of the image cache. When the specified retention period ends, the image cache is deleted. Unit: days.

AutoMatchImageCache

Boolean

false

Specifies whether to enable image cache reuse. If you enable this feature and the image cache that you want to create and an existing image cache contain duplicate image layers, the system reuses the duplicate image layers to create the new image cache. This accelerates the creation of the image cache. Default value: false.

Flash

Boolean

true

Specifies whether to enable the instant image cache feature. This feature can accelerate the creation of image caches. Default value: false.

When you create an image cache, you can use Container Registry (ACR) Enterprise Edition to pull images without the need to enter the password. The following table describes the parameters configured to use ACR. For more information, see Configure password-free access to pull images from a Container Registry Enterprise Edition instance.

Parameter

Type

Example

Description

AcrRegistryInfo.N.Domain.N

String

test****-registry.cn-beijing.cr.aliyuncs.com

Domain name N of Container Registry Enterprise Edition instance N. All domain names of instance N are displayed by default. You can specify domain names. Separate multiple domain names with commas (,).

AcrRegistryInfo.N.InstanceName

String

test****

The name of Container Registry Enterprise Edition instance N.

AcrRegistryInfo.N.InstanceId

String

cri-nwj395hgf6f3****

The ID of Container Registry Enterprise Edition instance N.

AcrRegistryInfo.N.RegionId

String

cn-beijing

The region ID of Container Registry Enterprise Edition instance N.

The following example shows how to use an SDK for Python and the ACR Enterprise Edition to pull images without the need to enter the password when an image cache is created.

from aliyunsdkcore.client import AcsClient
from aliyunsdkeci.request.v20180808.CreateImageCacheRequest import CreateImageCacheRequest

client = AcsClient('', '', 'cn-beijing')

request = CreateImageCacheRequest()
request.set_accept_format('json')

request.set_SecurityGroupId("sg-2zeh4cev9y7ulbr****")
request.set_VSwitchId("vsw-2zejlv7xjnw61w6zr****")
request.set_ImageCacheName("acr-test-cache")
request.set_Images([
    "****-registry-vpc.cn-beijing.cr.aliyuncs.com/eci_test/nginx:1.0",
])
request.set_AcrRegistryInfos([
  {
    "InstanceId": "cri-nwj395hgf6f*****",
    "RegionId": "cn-beijing"
  }
])

response = client.do_action_with_exception(request)
print(str(response, encoding='utf-8'))

Create an image cache by using the Elastic Container Instance console

  1. In the left-side navigation pane of the Elastic Container Instance console, click Image cache. On the Image cache page, click Create image cache.

  2. On the page that appears, configure parameters.

    Image cache
  3. Read and select Elastic Container Instance (ECI) Service Agreement. Click Create and follow the on-screen instructions to complete the subsequent operations.

  4. Go back to the Image cache page to view the new image cache.

    The state of the image cache is displayed in the Status column. When the state changes to Ready, the image cache is created. Click the ID of the image cache to go to the details page. View the basic information and events about the image cache.

Query an image cache

After you create an image cache, you can query the information about the image cache. You can use the image cache if the image cache is in the Ready state.

You can use one of the following methods to query an image cache:

  • Call the DescribeImageCaches API operation. For more information, see DescribeImageCaches.

  • In the Elastic Container Instance console, go to the Image cache page to view the information about an image cache such as its name and status. You can also click the ID of an image cache to view details such as events about the image cache.

Update an image cache

If an image cache is in the Ready or UpdateFailed state, you can call the UpdateImageCache API operation to update the image cache, such as updating the container image, retention period, and image repository of the image cache. For more information, see UpdateImageCache.

Deletes an image cache

A snapshot is created for each image cache. To retain an image cache, you are charged for the snapshot. If you do not specify a retention period for an image cache, we recommend that you delete the image cache when it is no longer needed.

Note

Automatic image cache snapshots are managed by Alibaba Cloud. The system automatically deletes automatic image cache snapshots that are not used within 3 days after they are created.

You can use one of the following methods to delete an image cache: