This topic describes how to use a Container Registry Personal Edition instance to create an image repository, configure build rules, and build images.

Description

Note If you have higher requirements for repository creation and image build, for example, you want to use features such as flexible configurations, custom parameters, and multi-architecture build, we recommend that you use Container Registry Enterprise Edition instances. For more information, see Use Container Registry Enterprise Edition instances to build images.
Before you build an image in the Container Registry Personal Edition instance, take note of the following items for the base image in the Dockerfile:
  • The base image is publicly-accessible.
  • The base image can be a public image that belongs to the same account and region as the Container Registry Personal Edition instance.
  • If the base image is deployed in a Container Registry Personal Edition instance, the Container Registry Personal Edition instance that hosts the base image must be in the same region as the Container Registry Personal Edition instance that is used to build the image.
  • The base image cannot be pulled from a VPC regardless of the region.
  • The base image cannot be an image provided by a third party.

For example, you can specify a publicly-accessible image of the Container Registry Personal Edition instance as the base image in the Dockerfile. However, you cannot specify an image that is provided by a third party.

Features

  • Automatically build images when code changes

    After you turn on Automatically Build Images When Code Changes, an image is automatically built each time you commit the code. This reduces manual workload.

    1. Log on to the Container Registry console.
    2. In the top navigation bar, select a region.
    3. In the left-side navigation pane, click Instances.
    4. On the Instances page, click the default instance.
    5. On the management page of the Container Registry Personal Edition instance, choose Repository > Repositories in the left-side navigation pane.
    6. On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
    7. In the left-side navigation pane, click Build. On the page that appears, turn on Automatically Build Images When Code Changes.
    Automatically Build Images When Code Changes
  • Build images on servers outside the Chinese mainland
    The source code used for image building may be stored in a source code repository outside the Chinese mainland. Container Registry provides the Build With Servers Deployed Outside Chinese Mainland feature to help you build images from repositories outside the Chinese mainland. After an image is built on a server outside the Chinese mainland, the image is pushed to a repository in the specified region.
    Note Image pushes may time out if the cross-border network connection is unstable.
    Build images on servers outside the Chinese mainland
  • Build images without using cache

    After you turn on Build Without Cache, Container Registry pulls the base image from the source code repository each time you build an image. This may slow down the build process. We recommend that you turn off the switch.

  • Multi-stage builds

    Container Registry supports multi-stage builds.

Step 1: Bind a source code repository

You must bind your Container Registry instance to a source code repository. In this example, a GitHub repository is used.
Notice
  • You cannot build images from an on-premises code repository.
  • When you bind a private GitLab, you cannot bind a private GitLab in a VPC.
  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the default instance.
  5. On the management page of the Container Registry Enterprise Edition instance, choose Repository > Code Source in the left-side navigation pane.
  6. On the Code Source page, find GitHub and click Bind Account in the Actions column.
  7. In the GitHub dialog box, click Go to the source code repository to bind account.
  8. On the GitHub logon page, enter your username and password, and then click Sign in.

    You are automatically directed to the Container Registry console and the following message appears: You have successfully bound the GitHub account.

Step 2: Create a repository

Before you create a repository, make sure that a namespace is created in the specified region. For more information, see Manage namespaces.

  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the default instance.
  5. On the management page of the Container Registry Personal Edition instance, choose Repository > Repositories in the left-side navigation pane.
  6. On the Repositories page, click Create Repositories.
  7. On the Repository Info wizard page, set the Namespace, Repository Name, Summary, and Repository Type parameters. In this example, the Private type is selected. Click Next. Create Repositories
  8. On the Code Source wizard page, set the Code Source, Build Settings, and Build Rules parameters, and then click Create Repositories.
    Parameter Description
    Code Source Select the code source. In this example, GitHub is selected. Click the GitHub tab and then select the namespace and repository.
    Build Settings
    • Automatically Build Images When Code Changes: If you select this option, an image is automatically built when code is committed from a branch.
    • Build With Servers Deployed Outside Chinese Mainland: If you select this option, images are built in a data center outside the Chinese mainland and then pushed to the image repository.
    • Build Without Cache: If you select this option, the system pulls the base image from the source code repository each time an image is built. This may increase the build time. You can disable Build Without Cache to accelerate the build process.

Step 3: Configure build rules

Note If no source code repositories are bound to your instance, Build is not displayed on the repository management page. You can refer to Step 1 to bind a source code repository.
  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the default instance.
  5. On the management page of the Container Registry Personal Edition instance, choose Repository > Repositories in the left-side navigation pane.
  6. On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
  7. On the repository management page, click Build in the left-side navigation pane. In the Build Rules section, click Add Build Rule.
    Note To modify a build rule, select the rule that you want to modify and click Modify in the Actions column.
  8. In the Add Build Rule dialog box, configure the build rule and click Confirm. Add Build Rule
    Parameter Description
    Type Specifies the type of the source code repository. Valid values: Branch and Tag.
    Code Branch/Tag Specifies the code branch or tag that triggers the build rule.
    Dockerfile Directory The directory of the Dockerfile. Specifies the Dockerfile directory relative to the branch or tag directory. For example, if the branch directory is master and the Dockerfile is in the master directory, set the value to /.
    Dockerfile Filename The name of the Dockerfile. The default value is Dockerfile.
    Tags The tag of the image. In this example, latest is specified.

Step 4: Build an image

  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the default instance.
  5. On the management page of the Container Registry Personal Edition instance, choose Repository > Repositories in the left-side navigation pane.
  6. On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
  7. On the repository management page, click Build in the left-side navigation pane.
  8. In the Build Rules section, select the build rule that you want to use and click Build in the Actions column. Build
    After the build is complete, a build record is generated.
    Note Select the build record that you want to view and click Log in the Actions column to view the build log.
  9. After the image is built, click Tags in the left-side navigation pane to view the list of created images.

  10. To view all images, click Build in the left-side navigation pane. On the page that appears, turn on Build With Servers Deployed Outside Chinese Mainland and Build Without Cache and retain the default setting for Automatically Build Images When Code Changes in the Build Settings section. Then, you can view all of the images. Tags

What to do next