If you do not have high requirements on the number of namespaces, private repositories, and build rules, we recommend that you use Container Registry Default Instance that supports base images. This topic describes how to use Container Registry Default Instance to create a repository, set build rules, and build images.

Features

  • Container Registry supports automatically triggering an image build when the code changes.

    After you switch on Automatically Build Images When Code Changes, an automatic image build is triggered each time you commit the code. This lowers the manual workload.

    1. Log on to the Container Registry console. In the top navigation bar, select the target region.
    2. In the left-side navigation pane, choose Default Instance > Repositories.
    3. On the Repositories page, click Manage in the Actions column of the target repository.
    4. In the left-side navigation pane, click Build and then switch on Automatically Build Images When Code Changes.
    Automatically build image
  • Container Registry supports building images on an overseas machine.
    A source code repository outside China may be involved in building images. However, you may have no access to such a repository over the network. To resolve this issue, we provide the Build With Servers Deployed Outside Mainland China feature. After you build an image on an overseas machine, you can push the image to a repository in the specified region.
    Note Sometimes, image pushes may time out if the network over which images are transmitted from outside China to Mainland China is unstable.
  • Container Registry supports building images without cache.

    After you switch on Build Without Cache, the dependent base image is pulled each time you build an image. This may slow down the build time. We recommend that you switch off this option.

  • Container Registry supports multi-stage build.

Create a repository

Before creating a repository, make sure that a namespace is created in the target region. For more information, see Basic operations on a namespace.

  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region. In the left-side navigation pane, choose Default Instance > Repositories. On the Repositories page that appears, click Create Repository.

  3. In the Create Repository dialog box, set the namespace, repository name, repository type, and digest. In this example, set the repository type to Private. Then, click Next.
  4. In the Code Source step, set Code Source to Code and click Create Repository.
    • Automatically Build Images When Code Changes: If you select this check box, an automatic image build is triggered when code is committed from a branch.
    • Build With Servers Deployed Outside Mainland China: If you select this check box, images are built in a data center outside China and then pushed to repositories in the specified region.
    • Build Without Cache: If you select this check box, the system forcibly pulls the dependent base image each time you build an image. This may slow down the build time.

Set build rules

  1. Log on to the Container Registry console.
  2. Click Manage in the Actions column of the target repository to go to the repository details page.Manage a repository
  3. In the left-side navigation pane, click Build. On the page that appears, click Add Rule on the right side of the Build Rules section.
    Note To modify a build rule, click Modify in the Actions column of the target rule.
  4. Set a build rule and click OK.
    • Type: Select a type for the source code repository. Valid values: Branch and Tag.
    • Code Branch/Tag: Set the code branch for building images.
    • Dockerfile Directory: Set the directory for storing the Dockerfile. The specified directory is a relative directory, with the root directory of the code branch as its parent directory.
    • Dockerfile Filename: Set the Dockerfile filename. Default value: Dockerfile.
    • Tag: Set a tag for the image, for example, latest.

Build images

  1. Go to the repository details page. In the left-side navigation pane, click Build.
  2. In the Build Rules section, click Build in the Actions column of the target rule.Build

    After the image is built, a build record is generated.

  3. Click Log in the Actions column of the target record to view the log details.
  4. After the image is built, click Tags in the left-side navigation pane to view the list of created images.

    Tags
  5. To view all the images, click Build in the left-side navigation pane. On the page that appears, switch on Build overseas and Build without cache and retain the default setting for Automatically build image in the Build Settings section. You can then view all the tags.Tags

What to do next