This topic describes how to build a custom image for the NGINX development environment by using Image Builder and how to create an instance from the built image to test the environment.

Background information

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

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

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 > Auto Provisioning.
  3. In the top navigation bar, select a region.
  4. On the Image Builder Management page, click Create Image Template.
    If you access Image Builder for the first time, the Image Builder welcome page appears. Click Create Image Template.
  5. Configure parameters to create an image template. Then, click Create.
    This tutorial focuses on configuring the parameters in the Basic Information and Configure Source Image sections. For more information about how to configure other parameters for creating an image template, see Create an image template.
    • In the Basic Information section, configure Template Name, Description, and Tag.
    • In the Configure Source Image section, click Import Template through Dockerfile. Import your template content and click Parse.
      The following template content is used in this example:
      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
    • In the Configure Intermediate Instance section, configure resources such as the instance type, storage size, and public bandwidth of the intermediate instance.
      Note The default value of public bandwidth is 0. This value indicates that you cannot access the image template over the Internet. If your image building content contains a command such as a download command that requires to access the Internet, you must set a non-zero value for the public bandwidth. Otherwise, the image building task fails.
    • In the Configure Image Distribution section, you can configure the built image to be distributed to specified regions or to be shared to specified Alibaba Cloud accounts.
      The following configurations are used in the example in this tutorial.
      • Destination Image Name: the name prefix of the built image. The final image name consists of the prefix and the ID of the building task (ExecutionId). The name prefix of the built image is test-image in this example.
      • Current Region: Default distribution regions include China (Beijing).
      • Default Distribution Region: Enter China (Hangzhou).
      • Shared User ID: Specify an Alibaba Cloud account to share the image.
      • Execute Immediately: Select No.
  6. On the Image Template 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 building task is executed, the status of the building task changes to Status, and the image ID is generated.
    Note If the status is Failed, you can view the details of Execution Result to identify and troubleshoot the problem.

Step 2: View the built image

  1. On the Building History tab of the Detail page of the image template, click the image ID to go to the Detail page of the custom image.
  2. Click Object to Share to view the Alibaba Cloud accounts to which the image is shared.
  3. View the distribution of the 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.
      China (Hangzhou) is selected in this example.
    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 name prefix test-image of the destination image in the search box to search for the image. If you find the image, the image is distributed.
      Note The name of the distributed image is in the format of <The custom name prefix>_<The ID of the Building Task>. Therefore, you can use the ID of the building task to search for the distributed image.

Step 3: Create an instance and test the NGINX environment

  1. In the left-side navigation pane, choose Deployment & Elasticity > Auto Provisioning.
  2. In the top navigation bar, select the region where the image template is created.
    In this example, the image was built in the China (Beijing) region.
  3. On the Image Templates tab, find the built image template and click the template ID to go to the Detail page of the image template.
  4. On the Building History tab, click the image ID to go to the details page of the custom image.
  5. Click Create Instance to create an instance from the image.
    Create an ECS instance based on your business needs. Pay attention to the following configuration items. 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 the security group to allow traffic on port 80.
  6. Obtain the public IP address of the instance.
    1. After the instance is created, return to the Instances page.
    2. Find the created instance and copy the public IP address in the IP Address column.
  7. Open a browser in the local environment, and enter the <Public IP Address of the ECS instance> in the address bar to access the page.
    If the following page appears, the NGINX development environment works normally. Nginx