All Products
Search
Document Center

Elastic Compute Service:Best practice for Image Builder

Last Updated:Feb 06, 2024

Image Builder is an all-in-one Alibaba Cloud service that helps you automate the creation, management, validation, sharing, and distribution of custom images. This topic describes how to create a custom image that contains an NGINX development environment and use the custom image to create an Elastic Compute Service (ECS) instance to check whether the NGINX development environment can be accessed.

Background information

In this example, the following configurations are used:

  • Current region: China (Beijing)

  • Destination region to which to distribute the image: China (Hangzhou)

  • Public image: Alibaba Cloud Linux 3

  • Image content in the image template: NGINX development environment

Use the preceding configurations to create a custom image named test-image in the China (Beijing) region and distribute the custom image to the China (Hangzhou) region. Then, use the test-image image to create an ECS instance on which an NGINX development environment is deployed in the China (Hangzhou) region. Then, check whether you can access the NGINX development environment on the ECS instance from your on-premises machine. If you can access the NGINX development environment, the custom image works as expected.

Step 1: Create and execute an image template

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Deployment & Elasticity > icon1 > Image Builder.

  3. In the top navigation bar, select a region.

  4. On the Image Builder page, click the Image Templates tab. Then, click Create Image Template.

    The first time you access the Image Builder service, click Create Image Template on the Image Builder welcome page.

  5. Configure an image template and click OK.

    The following section describes the parameters in the Configure Source Image section. For more information about how to create an image template, see Create an image template and run a building task.

    • In the Basic Information section, configure the Template Name, Description, and Tag parameters.

    • Configure Source Image: Click Import Template through Dockerfile, import template content, and then click OK.

      In this example, the following template content is used:

      FROM IMAGE:aliyun_3_9_x64_20G_alibase_20231219.vhd
      LABEL author="admin" date="2024-01-15" platform="aliyun"
      RUN yum update -y
      RUN rpm --rebuilddb && yum install -y autoconf automake make wget net-tools zlib zlib-devel make gcc openssl-devel pcre pcre-devel tar
      RUN mkdir nginx_copy
      COPY http://nginx.org/download/nginx-1.17.1.tar.gz nginx_copy
      WORKDIR /root/nginx_copy
      USER root
      RUN tar -zxvf nginx-1.17.1.tar.gz
      ENV nginxversion nginx-1.17.1
      WORKDIR /root/nginx_copy/$nginxversion
      RUN ./configure --prefix=/usr/local/nginx && make && make install
      WORKDIR /usr/local/nginx
      ENTRYPOINT ["sbin/nginx","-c"]
      CMD conf/nginx.conf

      The system can automatically configure the image and build an image template.

    • In the Configure Intermediate Instance section, configure the Instance Type, System Disk Size, and Public Bandwidth (Mbps) parameters.

      Important

      By default, the Public Bandwidth (Mbps) parameter is set to 0. This value indicates that the intermediate instance does not have Internet connectivity. If your image template content contains a command that requires Internet connectivity, set Public Bandwidth (Mbps) to a non-zero value. Otherwise, the image building task fails.

    • In the Configure Image Distribution section, you can configure the created images to be distributed to specified regions or to be shared with specified Alibaba Cloud accounts.

      In this example, the following configurations are used:

      • Destination Image Name: Specify the name prefix of the images to be created. In this example, the name prefix is set to test-image.

      • Current Region: This parameter is automatically set to Default distribution regions include China (Beijing).

      • Destination Region: Select China (Hangzhou).

      • Shared User ID: Specify an Alibaba Cloud account.

      • Execute Immediately: Select No.

  6. On the Image Templates tab, find the created image template. In the Actions column, click Execute.

    You can click the ID of an image template to view the progress of the image building task on the Building History tab of the details page of the image template. If the image building task is successfully executed, Success is displayed in the Status column and an image ID is generated.

    Note

    If Failed is displayed in the Status column, you can check the error details displayed in the Execution Result column to identify and troubleshoot the issue.

Step 2: View the created image

  1. On the Building History tab of the Template Details page, click the image ID to go to the details page of the created image.

  2. Click the Sharing Information tab to view the Alibaba Cloud accounts with which the created image is shared.

  3. Check the distribution of the created image.

    1. In the left-side navigation pane, choose Instances & Images > Images.

    2. In the top navigation bar, select a region to which the image is distributed.

      In this example, select China (Hangzhou).

    3. On the Custom Images tab, view the distributed image.

      Note

      In this example, the image name prefix test-image is used to search for the image. The name of the distributed image is in the format of <Image name prefix>_<ID of the image building task>. You can also use the ID of the image building task to search for the image.

Step 3: Create an ECS instance from the image and test the NGINX development environment

  1. In the left-side navigation pane, choose Deployment & Elasticity > icon1 > Image Builder.

  2. In the top navigation bar, select the region in which the image template is created.

    In this example, the image is created in the China (Beijing) region.

  3. On the Image Templates tab, find the created image template and click the template ID to go to the Template Details page.

  4. On the Building History tab, click an image ID to go to the details page of the image.

  5. In the upper-right corner of the image details page, click Create Instance.

    Create an instance based on your business needs. Take note of the following items when you create the instance. For more information, see Create an ECS instance by using a custom image.

    • Select Assign Public IPv4 Address in the Public IP Address section.

    • Configure an inbound rule in a security group to open port 80.

  6. Obtain the public IP address of the ECS instance.

    1. After the instance is created, go to the Instances page.

    2. Find the created instance and copy the public IP address in the IP Address column.

  7. Open a browser on your computer, enter the <Public IP Address of the ECS instance> in the address bar, and then press the Enter key.

    If the following page appears, the NGINX development environment can be accessed.Nginx