This topic describes how to use a Container Registry Personal Edition instance to create an image repository, configure build rules, and build images.
Description
- 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.
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the default instance.
- On the management page of the Container Registry Personal Edition instance, choose in the left-side navigation pane.
- On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
- In the left-side navigation pane, click Build. On the page that appears, turn on .
- 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 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 cannot build images from an on-premises code repository.
- When you bind a private GitLab, you cannot bind a private GitLab in a VPC.
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the default instance.
- On the management page of the Container Registry Enterprise Edition instance, choose in the left-side navigation pane.
- On the Code Source page, find GitHub and click Bind Account in the Actions column.
- In the GitHub dialog box, click Go to the source code repository to bind account.
- 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.
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the default instance.
- On the management page of the Container Registry Personal Edition instance, choose in the left-side navigation pane.
- On the Repositories page, click Create Repositories.
- 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.
- 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
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the default instance.
- On the management page of the Container Registry Personal Edition instance, choose in the left-side navigation pane.
- On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
- 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.
- In the Add Build Rule dialog box, configure the build rule and click Confirm.
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
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the default instance.
- On the management page of the Container Registry Personal Edition instance, choose in the left-side navigation pane.
- On the Repositories page, find the repository that you want to manage and click Manage in the Actions column.
- On the repository management page, click Build in the left-side navigation pane.
- In the Build Rules section, select the build rule that you want to use and click Build in the Actions column. 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.
-
After the image is built, click Tags in the left-side navigation pane to view the list of created images.
- 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.