All Products
Search
Document Center

Use an image cache to create an elastic container instance

Last Updated: Jul 30, 2021

Image caches accelerate the image pulling process and reduce the startup time of elastic container instances. This topic describes how to create an image cache and then create an elastic container instance from the image cache by using the Elastic Container Instance console or by calling an API operation.

Background information

When you run containers, Elastic Container Instance must pull the specified images. It can take a long time to pull large images over an unstable network when elastic container instances start. To resolve this issue, you can use the image cache feature.

You are charged for creating and using image caches. Take note of the following items:

  • When an image cache is being created, an intermediate elastic container instance and an intermediate performance level-1 (PL1) enhanced SSD (ESSD) are created. The intermediate instance has two vCPUs and 4 GiB of memory. After the image cache is created, the instance and the ESSD are automatically released and no longer billed.

  • A snapshot is created for each image cache. You are charged for this snapshot based on its size and retention period, which are equal to the size and retention period of the image cache.

    Note

    If you enable the instant image cache feature to accelerate the creation of an image cache, the system creates a temporary local snapshot. You are charged the storage fee for the local snapshot and the fee for the instant access feature.

  • When you use an image cache to create an elastic container instance, the system creates a PL1 ESSD based on the snapshot of the image cache and attaches the ESSD to the elastic container instance. In addition to the instance fee, you must also pay the fee for this ESSD.

For more information, see the "Billing of image caches" section of the Overview topic.

Image caches can be manually or automatically created and then be used to create elastic container instances.

  • Manually create an image cache

    You can manually create an image cache and use the image cache to create elastic container instances.

  • Automatically create an image cache

    You can enable automatic creation of image caches. Then, if no image caches can be matched when you enable automatic match of image caches during the creation of an elastic container instance, the system automatically creates a matching image cache. You can skip the step of creating an image cache and proceed to create an elastic container instance.

    Note

    By default, the image cache feature is disabled. If you want to enable this feature, submit a ticket.

If you are using Container Service for Kubernetes (ACK) or Serverless Kubernetes (ASK), you can use the image cache feature in the form of a custom resource definition (CRD). For more information, see Use an image cache CRD to accelerate pod creation.

Create an image cache

If you have enabled automatic creation of image caches, you can skip this step and proceed to create an elastic container instance.

Precautions

Before you create an image cache, take note of the following items:

  • Each image cache can contain up to 20 images. You can customize the size of an image cache.

    • If you select private images that are not hosted in Alibaba Cloud Container Registry (ACR), you must specify the access credentials of the repository to which the private images belong, including the IP address, username, and password.

    • If your selected images cannot be pulled due to some reasons such as a timeout error of the remote registry, we recommend that you use ACR to upload the images to an Alibaba Cloud image registry.

    • If the selected images such as Docker images need to be pulled over the Internet, you must configure elastic IP addresses (EIPs) or NAT gateways for elastic container instances. For more information, see Enable Internet access.

  • You can enable the retention period feature and specify a retention period for retain an image cache. The image cache is automatically deleted when the specified retention period ends. By default, the retention period feature is disabled.

    Note

    A snapshot is created for each image cache. You are charged for the storage space consumed by 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.

  • The amount of time it takes to create an image cache is determined by a variety of factors including the total size of selected images and network conditions. If you create an image cache by calling an API operation, you can enable the instant image cache feature to accelerate the creation of the image cache. After the instant image cache feature is enabled, the system creates a temporary local snapshot in a quick manner by using the instant access feature. After the local snapshot is created, the image cache is immediately available for use

    Note

    and the system begins to create a normal snapshot. While the system is creating the normal snapshot, the image cache uses the local snapshot. After the normal snapshot is created, the system deletes the local snapshot and the image cache begins to use the normal snapshot.

Create an image cache by calling an API operation

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

Parameter

Type

Example

Description

RegionId

String

cn-hangzhou

The ID of the region in which to create 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

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.

RetentionDays

Integer

7

The retention period of the image cache. Unit: days. The image cache is automatically deleted when the retention period ends.

Flash

Boolean

true

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

After an image cache is created, you can call the DescribeImageCaches operation to query information of the image cache. For more information, see DescribeImageCaches.

Create an image cache by using the Elastic Container Instance console

  1. In the Elastic Container Instance console, go to the Image Caches page and 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 complete the subsequent operations as prompted.

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

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

Use the image cache to create an elastic container instance

You can create an elastic container instance from your image cache by calling an API operation or using the Elastic Container Instance console.

Notice

  • If no image caches can be matched, the system pulls an image. We recommend that you set the image pulling policy to On-demand (IfNotPresent). Otherwise, the use of image caches is affected.

  • After you enable automatic creation of image caches, you can optionally enable automatic match of image caches when you create an elastic container instance. Then, if no image caches can be matched, the system creates a matching image cache.

Create an elastic container instance from your image cache by calling an API operation

When you call the CreateContainerGroup operation to create an elastic container instance from an image cache, you can use the ImageSnapshotId parameter to specify the image cache or use the AutoMatchImageCache parameter to enable automatic match of image caches. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

ImageSnapshotId

String

imc-2zebxkiifuyzzlhl****

The ID of the image cache.

AutoMatchImageCache

Boolean

true

Specifies whether to enable automatic match of image caches.

Create an elastic container instance from your image cache by using the Elastic Container Instance console

  1. In the Elastic Container Instance console, go to the Elastic Container Instance page and click Create Elastic Container Group.

  2. On the page that appears, configure parameters.

    In the Container Group Configuration section, expand Advanced Settings and select Automatically Match Image Cache to enable automatic match of image caches. Then, the system matches and uses the most suitable image cache.Image cache 2

  3. Click Confirm Configuration and complete the subsequent operations as prompted.

View the created elastic container instances

In the Elastic Container Instance console, go to the Elastic Container Instance page. Find an elastic container instance created from your image cache and click the instance ID to go to the details page. On the Event tab, you can find the image cache that the instance matches. Images can be pulled nearly instantaneously.

Image cache 1