This topic describes how to create a custom image for the NGINX development environment by using Image Builder and how to create an Elastic Compute Service (ECS) instance from the custom image and test the environment.

Background information

Image Builder is a service provided by Alibaba Cloud that integrates image customization, creation, maintenance, verification, sharing, and distribution. You can use Image Builder to create images and update or roll back applications within the images. For more information, see Overview.

In the examples, the following configurations are used:
  • Region: China (Beijing)
  • Public image: CentOS 8.2 64-bit
  • Image content in the image template: NGINX development environment
An image is created based on the preceding configurations, and then an instance is created from the image and is used to test whether the NGINX environment works normally.

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 > Image Builder.
  3. In the top navigation bar, select a region.
  4. On the Image Builder Management page, click Create Image Template.
    The first time you access Image Builder, the Image Builder welcome page appears. Click Create Image Template.
  5. On the Create Image Template page, configure parameters and click Create.
    This section describes the parameters in the Configure Source Image section. For information about how to configure other parameters, see Create an image template.
    • In the Basic Information section, configure the Template Name, Description, and Tag parameters.
    • In the Configure Source Image section, click Import Template through Dockerfile. In the dialog box that appears, enter text in code editor and click Parse.
      In this example, enter the following data in the code editor:
      FROM IMAGE:centos_8_2_x64_20G_alibase_20201120.vhd
      LABEL author="admin" date="2020-11-28" platform="centos"
      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 nginx_copy
      USER root
      RUN tar -zxvf nginx-1.17.1.tar.gz
      ENV nginxversion nginx-1.17.1
      WORKDIR $nginxversion
      RUN ./configure --prefix=/usr/local/nginx && make && make install
      WORKDIR /usr/local/nginx
      ENTRYPOINT ["sbin/nginx","-c"]
      CMD conf/nginx.conf
      After the entered data is parsed, the Image and Image Template parameters are automatically configured, as shown in the following figure. Image content in the image template
    • In the Configure Intermediate Instance section, configure the Instance Type, System Disk Size, Public Bandwidth (Mbit/s) parameters.
      Note By default, Public Bandwidth (Mbit/s) is set to 0. This value indicates that the intermediate instance cannot access the Internet. If your image content contains a command that requires access to the Internet, you must set Public Bandwidth to a non-zero value. Otherwise, the image creation task fails.
    • In the Configure Image Distribution section, you can configure the created image to be distributed to specified regions or to be shared to specified Alibaba Cloud accounts.
      In this example, the following configurations are used:
      • Destination Image Name: Specify the name prefix of the image to be created. In this example, a name prefix of test-image is used. The system appends the ID of the image creation task to the prefix to generate a name for the image.
      • Current Region: is set to Default distribution regions include China (Beijing).
      • Default Distribution Region: Enter China (Hangzhou).
      • Shared User ID: Specify an Alibaba Cloud account.
      • Execute Immediately: Select No.
  6. On the Image Templates tab of the Image Builder Management page, find the created image template. Click the template ID in the Template Name column to go to the Detail page of the image template.
  7. On the Building History tab, click Execute.
    After the image creation task is executed, the State icon is displayed in the Status column, and the corresponding image ID is generated in the Image ID column.
    Note If Failed is displayed in the Status column, you can view the details of Execution Result to identify and troubleshoot the error.

Step 2: View the created image

  1. On the Building History tab of the Detail page of the image template, click the image ID to go to the details page of the created image.
  2. Click Object to Share to view the Alibaba Cloud accounts to 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 the region to which the image is distributed.
      In this example, select China (Hangzhou).
    3. On the Custom Image tab, select Image Name from the drop-down list and enter the name of the distributed image in the search box to search for the image.
      Enter the test-image name prefix. If the image is distributed to the selected region, you can find the image in the search result.
      Note The name of the distributed image is in the format of <Image name prefix>_<ID of the Image creation task>. Therefore, you can use the ID of the image creation task to search for the distributed image.
      Image distribution

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

  1. In the left-side navigation pane, choose Deployment & Elasticity > 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 Detail page of the image template.
  4. On the Building History tab, click an image ID to go to the details page of the image.
  5. Click Create Instance in the Actions column corresponding to the image to create an instance.
    Create an instance based on your business needs. Take note of the following configuration 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 in the Networking step.
    • Configure an inbound rule in a security group to allow traffic on port 80.
  6. Obtain the public IP address of the instance.
    1. After the instance is created, go back 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 works normally. Nginx