All Products
Search
Document Center

Create an elastic container instance by using an image cache

Last Updated: Apr 14, 2021

Image caches accelerate image pulling 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 API operations.

Background information

To run containers, Elastic Container Instance must pull the specified images. It takes 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 enhanced SSD (ESSD) at performance level 1 (PL1) are created. The intermediate elastic container instance has two vCPUs and 4 GiB of memory. After the image cache is created, the elastic container 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.

  • 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 for the fee of this ESSD.

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

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 you select Automatically Match Image Cache when you create an elastic container instance but no image caches are matched, the system automatically creates a matching image cache. You can skip the step of creating an image cache when you create an elastic container instance.

    Note

    By default, automatic creation of image caches is disabled. If you want to enable this feature, submit a ticket.

If you are using a Container Service for Kubernetes (ACK) or serverless Kubernetes (ASK) cluster, you can use image caches in the form of custom resource definitions (CRDs). 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 create an elastic container instance.

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 the image cache.

  • You can specify a retention period for the image cache. The image cache is automatically deleted when the retention period ends. By default, the retention period is not specified.

    Note

    A snapshot is created for each image cache. You are charged for the storage of created snapshots. If image caches do not have a specified retention period, we recommend that you delete the image caches when they are no longer needed.

  • If you select private images that are not hosted by Alibaba Cloud Container Registry (ACR), specify the access credentials of the private image repository, including the address, username, and password.

  • If selected images fail to be pulled due to 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 create an image cache by using the Elastic Container Instance console or by calling an API operation.

  • 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 caches
    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 status 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.

  • OpenAPI

    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

    Required

    Example

    Description

    RegionId

    String

    Yes

    cn-hangzhou

    The ID of the region in which to create the image cache.

    ImageCacheName

    String

    Yes

    testcache

    The name of the image cache.

    Image.N

    RepeatList

    Yes

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

    The container image used to create the image cache.

    SecurityGroupId

    String

    Yes

    sg-uf66jeqopgqa9hdn****

    The ID of the security group.

    VSwitchId

    String

    Yes

    vsw-uf6h3rbwbm90urjwa****

    The ID of the vSwitch.

    ImageCacheSize

    Integer

    No

    20

    The size of the image cache.

    RetentionDays

    Integer

    No

    7

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

    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 elastic container instance by using an image cache

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

Notice

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

  • If you have enabled automatic creation of image caches and no image caches are matched after you select Automatically Match Image Cache on the instance buy page, the system automatically creates a matching image cache.

  • Create an elastic container instance from an 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, you can select Automatically Match Image Cache. Then, the system automatically matches and uses the most suitable image cache.

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

  • OpenAPI

    When you call the CreateContainerGroup operation to create an elastic container instance from the image cache, you can use the ImageSnapshotId parameter to specify an image cache or use the AutoMatchImageCache parameter to enable the Automatic Image Cache Match feature. The following table describes the parameters. For more information, see CreateContainerGroup.

    Parameter

    Type

    Required

    Example

    Description

    ImageSnapshotId

    String

    No

    imc-2zebxkiifuyzzlhl****

    The ID of the image cache.

    AutoMatchImageCache

    Boolean

    No

    true

    Specifies whether to enable the Automatic Image Cache Match feature.

View the created elastic container instance

In the Elastic Container Instance console, go to the Elastic Container Instance page. Find the elastic container instance created from the 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. Nearly no time is spent in pulling images.

Image cache 1