全部产品
Search
文档中心

云服务器 ECS:CreateImageComponent - 创建镜像组件

更新时间:Jun 25, 2026

创建一个镜像组件。镜像组件用于存储您在构建镜像时,常用的构建模板命令。

接口说明

接口说明

创建镜像组件前,您需要注意:

  • 仅支持创建您自定义的镜像组件。

  • 相同名称的组件版本号不能重复,当在模板中使用组件时,可以通过名称和版本号进行引用。

  • 镜像组件的内容大小不能超过 16 KB。支持的命令详情,请参见镜像构建服务支持的命令说明

更多信息,请参见镜像构建概述

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

调试

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。

  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。

  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:

    • 对于必选的资源类型,用前面加 * 表示。

    • 对于不支持资源级授权的操作,用全部资源表示。

  • 条件关键字:是指云产品自身定义的条件关键字。

  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。

操作

访问级别

资源类型

条件关键字

关联操作

ecs:CreateImageComponent

create

*ImageComponent

acs:ecs:{#regionId}:{#accountId}:imagecomponent/*

请求参数

名称

类型

必填

描述

示例值

RegionId

string

所属的地域 ID。您可以调用 DescribeRegions 查看最新的阿里云地域列表。

cn-hangzhou

ResourceGroupId

string

企业资源组 ID。

rg-bp67acfmxazb4p****

Tag

array<object>

标签列表。

object

Key

string

标签键。N 的取值范围:1~20。一旦传入该值,则不允许为空字符串。最多支持 128 个字符,不能以 aliyun 和 acs:开头,不能包含 http://或者 https://。

TestKey

Value

string

标签值。N 的取值范围:1~20。一旦传入该值,可以为空字符串。最多支持 128 个字符,不能以 acs:开头,不能包含 http://或者 https://。

TestValue

Name

string

组件名称。长度为 2~128 个字符,必须以大小写字母或中文开头,不能以 http://和 https://开头。可以包含中文、英文、数字、半角冒号(:)、下划线(_)、半角句号(.)或者短划线(-)。

说明

不设置Name时,默认使用ImageComponentId返回值。

testComponent

Description

string

描述信息。长度为 2~256 个英文或中文字符,不能以 http://和 https://开头。

This is description.

SystemType

string

组件支持的操作系统。

取值范围:

  • Linux

  • Windows

默认值:Linux。

Linux

ComponentType

string

组件类型。支持镜像构建组件和测试组件。

取值范围:

  • Build

  • Test

默认值:Build。

说明

构建组件只能在构建模板中使用,测试组件只能在测试模板中使用。

Build

Content

string

组件内容。由多条命令组成,命令内容不能超过 16KB。支持的命令和命令格式详情,请参见镜像构建服务支持的命令说明

Tasks: - Name: HelloWorld Action: RunShellCommand Properties: commandContent: echo hello world

ClientToken

string

保证请求幂等性。从您的客户端生成一个参数值,确保不同请求间该参数值唯一。ClientToken 只支持 ASCII 字符,且不能超过 64 个字符。更多信息,请参见如何保证幂等性

123e4567-e89b-12d3-a456-426655440000

ComponentVersion

string

组件版本号,与组件名称配合使用,格式为 major.minor.patch,均为非负整数。

默认值:(x+1).0.0,x 为当前组件最大的 major 版本号。

1.0.0

返回参数

名称

类型

描述

示例值

object

ImageComponentId

string

镜像组件 ID。

ic-bp67acfmxazb4p****

RequestId

string

请求 ID。

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

示例

正常返回示例

JSON格式

{
  "ImageComponentId": "ic-bp67acfmxazb4p****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

错误码

HTTP status code

错误码

错误信息

描述

400 InvalidCommand.Component Image component does not support component command.
400 InvalidName.Malformed %s
400 InvalidDescription.Malformed %s
400 InvalidSystemType.NotSupportedValue %s
400 InvalidComponentType.NotSupportedValue %s
400 InvalidContent.LengthExceeded %s
400 InvalidImageTemplateCommandSize.ExceededMaxNumber %s
400 InvalidImageTemplateCommand.NotSupported %s
400 InvalidCommandContent.RUN %s
400 InvalidCommandContent.ENV %s
400 InvalidCommandContent.WORKDIR %s
400 InvalidCommandContent.COPY %s
400 InvalidCommandContent.USER %s
400 InvalidCommandContent.CMD %s
400 InvalidCommandContent.ENTRYPOINT %s
400 MissingParameter.Content %s
400 EmptyCommandContent.RUN %s. 模版内容中,若有RUN命令,则RUN的值不能为空。
400 EmptyCommandContent.ENV %s. 模版内容中,若有ENV,则ENV的值不能为空。
400 EmptyCommandContent.LABEL %s. 模版内容中,若有LABEL,则LABEL的值不能为空。
400 EmptyCommandContent.COPY %s. 模版内容中,若有COPY命令,则COPY的值不能为空。
400 EmptyCommandContent.ENTRYPOINT %s. 模版内容中,若有ENTRYPOINT,则ENTRYPOINT的值不能为空。
400 EmptyCommandContent.CMD %s. 模版内容中,若有CMD命令,则CMD的值不能为空。
400 NotEmptyCommandContent.RESTART %s. 模版内容中,若有RESTART命令,则RESTART的值必须为空。
400 EmptyCommandContent.WORKDIR %s. 模版内容中,若有WORKDIR命令,则WORKDIR的值不能为空。
400 EmptyCommandContent.USER %s. 模版内容中,若有USER命令,则USER的值不能为空。
400 QuotaExceed.ImageComponent %s. 当前地域的镜像组件额度已用完。
400 InvalidParameter.Content %s. 镜像组件内容不合法。
400 InvalidImage.OsTypeUnsupported The specified base image does not support image building. 指定的基础镜像操作系统不支持进行镜像构建。
400 InvalidParameter.ComponentVersion The specified ComponentVersion is invalid. 指定的组件版本无效。
403 InvalidComponentVersion.Exist The specified ComponentVersion does exist with the specified Name. 该组件指定的版本号已经存在。
403 InvalidOperation.NoPermissionCreateServiceLinkedRole You are not authorized to create Service-linked role. The system will automatically create it when the API is called for the first time. Check your RAM policies, and ensure that you are using the correct credentials. 你没有权限创建服务关联角色,系统会在该接口第一次被调用时自动创建服务关联角色。请检查你的RAM权限策略,确保使用了正确的访问凭据。
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. 资源组并不在记录中。
404 NotSupportedCommand.FROM %s

访问错误中心查看更多错误码。

变更历史

更多信息,参考变更详情