The image building diagnosis feature identifies exceptions, potential risks, and opportunities to optimize your image build process. This topic describes the diagnostic checks and provides repair suggestions.
Image building diagnosis overview
The image building diagnosis feature combines expert experience with the AI capabilities of Tongyi Qianwen to precisely locate the root cause of issues and provide actionable repair suggestions.
When you use the image building diagnosis feature, the service collects data related to your Container Registry (ACR) instance. This data includes instance information, image building configuration, build task logs, and image build history. Do not store sensitive data in your image building configuration or output it to build task logs. For more information, see Usage notes.
The diagnosis feature consists of two main parts:
-
Rule detection: Includes instruction checks and error log analysis.
-
Root cause analysis: Includes the identified root cause and repair suggestions.
The service collects relevant data from your Container Registry (ACR) instance and identifies anomalies. It then performs an in-depth diagnosis to determine the root cause of issues and proposes solutions.
Diagnosis process
Image building diagnosis first collects the necessary data from your Container Registry (ACR) instance and then performs an in-depth analysis of any exceptions. After you initiate a diagnosis, the process consists of three stages:
-
Data preprocessing: Collects required data, such as instance status, repository configuration, build rule information, and build logs, to quickly analyze build exceptions.
-
Rule detection: Analyzes the collected data to identify exceptions, potential risks, and opportunities to optimize the build process.
-
Root cause analysis: Automatically determines the root cause of issues and provides repair suggestions, based on the collected data and detected items.
Diagnosis results
The diagnosis results include two parts:
-
Items to be fixed: Includes the root cause of the exception, a repair suggestion, and the location of the exception.
-
AI diagnosis: Analyzes build instructions or configuration items in-depth based on exception details to provide comprehensive optimization suggestions.
Diagnosis rules and repair suggestions
-
On the Image Build Diagnostics page, click Diagnostics. In the Select Image Build Task panel that appears, select the image build task to diagnose using the following parameters.
-
Namespace: The namespace to which the image build task belongs.
-
Repositories: The image repository to which the image build task belongs.
-
Image Build Task ID: The ID of the image build task.
After making your selections, carefully read the notes, select I understand and agree, and then click Initiate Diagnostics.
-
-
After the diagnosis is complete, you can take action based on the repair suggestions on the page. The following table describes common diagnosis rules, root causes of exceptions, and their corresponding repair suggestions.
Diagnosis rule group
Diagnosis rule name
Root cause
Repair suggestion
Dockerfile syntax detection
Invalid port definition
The port or protocol format in the
EXPOSEinstruction is incorrect.When using the
EXPOSEinstruction, ensure the port is a number between 0 and 65535, and the protocol is TCP or UDP.Copy instruction syntax detection
The destination path is not a directory when copying multiple source files.
Ensure the destination path is a directory.
Build stage does not exist
The build stage specified by the
COPYinstruction does not exist.Ensure the stage name refers to a previously defined build stage.
Duplicate stage name
A build stage name is reused.
Avoid using duplicate build stage names.
Invalid first instruction
The first instruction is not
FROMorARG.Ensure the first instruction is
FROMorARG.Compilation error
A precompilation error occurred in the Dockerfile.
Correct the syntax errors in the Dockerfile or wait for the repair suggestion from the root cause analysis.
Compilation warning
A precompilation warning occurred in the Dockerfile.
Review the relevant instructions in the Dockerfile, as they may not run as expected.
Image tag detection
Base image tag not specified
No specific image tag is provided for the base image.
Specify a fixed image tag. Using an unspecified tag (which defaults to
latest) makes your build unpredictable, as the base image can change unexpectedly.Base image does not exist
The base image name is incorrect or the image does not exist.
Check the base image name or select a different base image that exists.
Runtime error detection
Command execution error
A command failed to run.
Check if the command specified in the Dockerfile is correct, or wait for the repair suggestion from the root cause analysis.
Command does not exist
The specified command does not exist.
Ensure the command specified in the Dockerfile exists in the base image.
File does not exist
A source file or directory in a
COPYinstruction does not exist.Verify that the file or directory referenced by the
COPYcommand in the Dockerfile exists in the build context.Invalid instruction detection
Invalid command detection
The Dockerfile contains unsupported instructions such as
KillorShutdown.Using instructions such as
KillorShutdownin the build process can cause security and stability issues. You must remove these instructions.sudo command detection
The
sudocommand is ineffective in a build process.Remove the
sudoinstruction.Upload stage error detection
Tag conflict
The image tag conflicts with an existing image tag in the repository.
To resolve the image tag conflict, disable the tag immutability feature for the repository or avoid repeatedly pushing an image with the same tag.
Image size optimization detection
Potential optimization for
apt-getinstructionsThe
apt updateandapt installcommands are in separate instructions.Separating the
apt updateandapt installinstructions can increase the image size and reduce the efficiency of repeated builds.Potential optimization for
apt-getinstructionsThe
apt-get installcommand runs without the--no-install-recommendsparameter.To reduce the image size, add the
--no-install-recommendsparameter to yourapt-get installcommand.Potential optimization for package installation
Package manager cache is not cleared after package installation.
To reduce the image size, clear the cache after you install packages. For example, use the
apt-get cleancommand for Ubuntu, use theapk addcommand with the--no-cacheflag for Alpine, or use theyum clean allcommand for CentOS.Multi-stage build detection
The Dockerfile does not use a multi-stage build to separate build-time dependencies from the final image.
Use a multi-stage build to compile your application in a separate build stage, and then copy the resulting artifacts to the final image. This can significantly reduce the final image size.
Redundant compressed packages
Downloaded archives are not cleaned up after extraction.
To reduce the image size, combine the download, extraction, and cleanup commands for compressed packages into a single
RUNinstruction.Build instruction optimization detection
Relative path detection
The
WORKDIRinstruction uses a relative path.Using a relative path with
WORKDIRcan lead to an unexpected working directory and cause build failures. Use an absolute path for clarity and reliability.Root user detection
The
USERinstruction switches to the root user.Switching to the root user during the build creates a security risk when the container is running. You must remove this instruction.
Path switching optimization detection
A
RUNinstruction uses thecdcommand to change directories.The effect of a
cdcommand is limited to theRUNinstruction in which it appears. To set the working directory for subsequent instructions, use theWORKDIRinstruction instead.CMDorENTRYPOINToverride detectionThe Dockerfile contains multiple
CMDorENTRYPOINTinstructions.If you use multiple
CMDorENTRYPOINTinstructions, only the last one takes effect. Ensure the final instruction is the one you intend to use.