All Products
Search
Document Center

Container Registry:Create a repository and build images

Last Updated:Sep 19, 2024

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

Usage notes

Note

The timeout period for image building of Personal Edition is set to 30 minutes. If you have higher requirements for repository creation and image building, for example, if you want to use flexible configurations, custom parameters, and multi-architecture building, we recommend that you use Container Registry Enterprise Edition instances. For more information, see Use a Container Registry Enterprise Edition instance to build an image.

Before you use a Container Registry Personal Edition instance to build images, make sure that the base image in the Dockerfile meets the following requirements:

  • The base image can be a publicly-accessible Internet image that does not require authorization.

  • The base image can be a private Internet image that belongs to the same account and region as the Container Registry Personal Edition instance.

  • The base image cannot be a private image that resides in a region different from the Container Registry Personal Edition instance.

  • The base image cannot be pulled from a virtual private cloud (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 Internet 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

Note

To build images, you must bind a source code repository. After you create your Personal Edition instance, bind a source code repository to the instance.

  • 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 Personal Edition instance that you want to manage.

    5. In the left-side navigation pane of the management page of the Personal Edition instance, choose Repository > Repositories.

    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.

    代码变更时自动构建镜像

  • 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 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 building process. We recommend that you turn off the switch.

  • Multi-stage building

    Container Registry supports multi-stage building.

Step 1: Bind a source code repository

You must bind a source code repository to your Container Registry Personal Edition instance. In this example, a GitHub repository is used.

Important
  • You cannot build images from an on-premises code repository.

  • For information about how to bind a private GitLab code repository in a VPC, see Build a container image 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 Personal Edition instance that you want to manage.

  5. In the left-side navigation pane of the management page of the Container Registry Private Edition instance, choose Repository > Code Source.

  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 redirected to the Container Registry console and the following message appears: You have successfully bound the GitHub account.

Step 2: Create an image repository

Before you create an image 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 Personal Edition instance that you want to manage.

  5. In the left-side navigation pane of the management page of the Personal Edition instance, choose Repository > Repositories.

  6. On the Repositories page, click Create Repository.

  7. In the Repository Info step, configure Namespace, Repository Name, Repository Type, and Summary. In this example, select Private for Repository Type. Then, click Next.

  8. In the Code Source step, configure Code Source, Build Settings, and Build Rules, and then click Create Repository.

    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: The building rule is automatically triggered when code is committed from a branch.

    • Build With Servers Deployed Outside Chinese Mainland: Images are built in a data center outside the Chinese mainland and then pushed to an image repository in the specified region. If the resources such as the source code repository and container image repository that you use to build the image are deployed in the Chinese mainland, we recommend that you disable the Build With Servers Deployed Outside Chinese Mainland feature to use servers deployed in the Chinese mainland.

    • Build Without Cache: The system pulls the base image from the source code repository each time an image is built. This may increase the building duration. You can disable Build Without Cache to accelerate the image building.

Step 3: Configure building rules

Note

If you cannot find Build on the repository management page, the code source fails to be bound to the Personal Edition instance. You can refer to Step 1 to rebind a code source.

  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 Personal Edition instance that you want to manage.

  5. In the left-side navigation pane of the management page of the Personal Edition instance, choose Repository > Repositories.

  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 of the repository management page, click Build. In the Build Rules section, click Add Build Rule.

    Note

    If you want to modify a building 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 building rule and click Confirm.构建个人版

    Parameter

    Description

    Type

    The type of the source code repository. Valid values: Branch and Tag.

    Branch/Tag

    The code branch or tag that triggers the build rule.

    Build Context Directory

    The directory of the Dockerfile. This is a subdirectory of the branch or tag directory. For example, if the branch directory is Master/ and the Dockerfile is in the Master/ directory, the value of this parameter is Master/Dockerfile.

    Dockerfile Filename

    The name of the Dockerfile. The default value is Dockerfile.

    Tags

    The tags 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 Personal Edition instance that you want to manage.

  5. In the left-side navigation pane of the management page of the Personal Edition instance, choose Repository > Repositories.

  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 of the repository management page, click Build.

  8. In the Build Rules section, select the building rule that you want to use and click Build in the Actions column.

    After the building rule is built, a building record is generated.

    Note

    Select the building record that you want to view and click Log in the Actions column to view the building log.

  9. After the image is built, click Tags in the left-side navigation pane to view the created images.

  10. To view all images, click Build in the left-side navigation pane. On the Build Settings section of the page that appears, turn on Build with Servers Deployed Outside Chinese Mainland and Build Without Cache and remain the default enabled status of Automatically Build Images When Code Changes. Then, click Tags in the left-side navigation pane to view all image tags.

What to do next