

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 提供的 Docker 镜像 CodeBuild
<a name="build-env-ref-available"></a>

*支持的映像是中可用图像*的最新主要版本，并通过次要版本 CodeBuild 和补丁版本更新进行更新。 CodeBuild 通过将支持的映像缓存到计算机的 [Amazon 系统映像 (AMI)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html#ami-using) 中，优化构建版本的配置时长。如果您想从缓存中受益并最大限度地缩短构建的配置持续时间，请在 CodeBuild 控制台的 “**映像版本” 部分中选择 “始终使用此运行时版本的最新****映像**”，而不是更精细的版本，例如`aws/codebuild/amazonlinux-x86_64-standard:4.0-1.0.0`。

**Topics**
+ [获取当前 Docker 映像的列表](build-env-ref-available-get.md)
+ [EC2 计算映像](ec2-compute-images.md)
+ [Lambda 计算映像](lambda-compute-images.md)
+ [已弃用的图片 CodeBuild](deprecated-images.md)
+ [可用的运行时](available-runtimes.md)
+ [运行时版本](runtime-versions.md)

# 获取当前 Docker 映像的列表
<a name="build-env-ref-available-get"></a>

CodeBuild 经常更新 Docker 镜像列表以添加最新镜像并弃用旧镜像。要获取最新列表，执行下列操作之一：
+ 在 CodeBuild 控制台的 “**创建构建项目” 向导或 **“编辑构建项目****” 页面中，为 “**环境映像**” 选择 “**托管映像**”。从**操作系统**、**运行时**和**运行时版本**下拉列表中进行选择。有关更多信息，请参阅[创建构建项目（控制台）](create-project.md#create-project-console)或[更改构建项目的设置（控制台）](change-project.md#change-project-console)。
+ 对于 AWS CLI，请运行以下`list-curated-environment-images`命令：

  ```
  aws codebuild list-curated-environment-images
  ```
+ 对于 AWS SDKs，请调用目标编程语言的`ListCuratedEnvironmentImages`操作。有关更多信息，请参阅[AWS SDKs 和工具参考](sdk-ref.md)。

# EC2 计算映像
<a name="ec2-compute-images"></a>

AWS CodeBuild 支持以下 Docker 镜像，这些镜像可用于 EC2 计算。 CodeBuild

**注意**  
Windows Server Core 2019 平台的基本映像仅在以下区域可用：  
美国东部（弗吉尼亚州北部）
美国东部（俄亥俄州）
美国西部（俄勒冈州）
欧洲地区（爱尔兰）


| 平台 | 映像标识符 | 定义 | 
| --- | --- | --- | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-standard:4.0 | [al/standard/4.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/x86_64/standard/4.0) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-standard:5.0 | [al/standard/5.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/x86_64/standard/5.0) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-standard:6.0 | [al/standard/6.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/x86_64/standard/6.0) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-standard:corretto8 | [al/standard/corretto8](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/x86_64/standard/corretto8) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-standard:corretto11 | [al/standard/corretto11](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/x86_64/standard/corretto11) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-standard:2.0 | [al/aarch64/standard/2.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/aarch64/standard/2.0) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-standard:3.0 | [al/aarch64/standard/3.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/al/aarch64/standard/3.0) | 
| Ubuntu 20.04 | aws/codebuild/standard:5.0 | [ubuntu/standard/5.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/ubuntu/standard/5.0) | 
| Ubuntu 22.04 | aws/codebuild/standard:6.0 | [ubuntu/standard/6.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/ubuntu/standard/6.0) | 
| Ubuntu 22.04 | aws/codebuild/standard:7.0 | [ubuntu/standard/7.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/ubuntu/standard/7.0) | 
| Ubuntu 24.04 | aws/codebuild/standard:8.0 | [ubuntu/standard/8.0](https://github.com/aws/aws-codebuild-docker-images/tree/master/ubuntu/standard/8.0) | 
| Windows Server Core 2019 | aws/codebuild/windows-base:2019-1.0 | 不适用 | 
| Windows Server Core 2019 | aws/codebuild/windows-base:2019-2.0 | 不适用 | 
| Windows Server Core 2019 | aws/codebuild/windows-base:2019-3.0 | 不适用 | 
| Windows Server Core 2022 | aws/codebuild/windows-base:2022-1.0 | 不适用 | 

**注意**  
2024 年 11 月 22 日，基于 Linux 的标准运行时映像的别名已从 `amazonlinux2` 更新为 `amazonlinux`。无需手动更新，因为之前的别名仍然有效。

# Lambda 计算映像
<a name="lambda-compute-images"></a>

AWS CodeBuild 支持以下 Docker 镜像，这些镜像可在中进行 AWS Lambda 计算。 CodeBuild

**重要**  
使用 Lambda 计算或预留容量时，不支持 `on-failure` 属性。此属性仅适用于提供的 EC2 计算映像 CodeBuild。


**`aarch64` 架构**  

| 平台 | 映像标识符 | 定义 | 
| --- | --- | --- | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:dotnet6 | [al-lambda/aarch64/dotnet 6](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/dotnet6) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:dotnet8 | [al-lambda/aarch64/dotnet 8](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/dotnet8) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:go1.21 | [al-lambda/aarch64/go 1.21](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/go1.21) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:go1.24 | [al-lambda/aarch64/go 1.24](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/go1.24) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:corretto11 | [al-lambda/aarch64/corretto 11](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/corretto11) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:corretto17 | [al-lambda/aarch64/corretto 17](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/corretto17) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:corretto21 | [al-lambda/aarch64/corretto 21](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/corretto21) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:nodejs18 | [al-lambda/aarch64/nodejs 18](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/nodejs18) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:nodejs20 | [al-lambda/aarch64/nodejs 20](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/nodejs20) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:nodejs22 | [al-lambda/aarch64/nodejs 22](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/nodejs22) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:python3.11 | [al-lambda/aarch64/python 3.11](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/python3.11) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:python3.12 | [al-lambda/aarch64/python 3.12](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/python3.12) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:python3.13 | [al-lambda/aarch64/python 3.13](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/python3.13) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-aarch64-lambda-standard:ruby3.2 | [al-lambda/aarch64/ruby 3.2](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/ruby3.2) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-aarch64-lambda-standard:ruby3.4 | [al-lambda/aarch64/ruby 3.4](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/aarch64/ruby3.4) | 


**`x86_64` 架构**  

| 平台 | 映像标识符 | 定义 | 
| --- | --- | --- | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:dotnet6 | [al-lambda/x86\$164/dotnet 6](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/dotnet6) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:dotnet8 | [al-lambda/x86\$164/dotnet 8](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/dotnet8) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:go1.21 | [al-lambda/x86\$164/go 1.21](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/go1.21) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:go1.24 | [al-lambda/x86\$164/go 1.24](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/go1.24) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:corretto11 | [al-lambda/x86\$164/corretto 11](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/corretto11) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:corretto17 | [al-lambda/x86\$164/corretto 17](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/corretto17) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:corretto21 | [al-lambda/x86\$164/corretto 21](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/corretto21) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:nodejs18 | [al-lambda/x86\$164/nodejs 18](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/nodejs18) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:nodejs20 | [al-lambda/x86\$164/nodejs 20](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/nodejs20) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:nodejs22 | [al-lambda/x86\$164/nodejs 22](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/nodejs22) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:python3.11 | [al-lambda/x86\$164/python 3.11](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/python3.11) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:python3.12 | [al-lambda/x86\$164/python 3.12](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/python3.12) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:python3.13 | [al-lambda/x86\$164/python 3.13](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/python3.13) | 
| Amazon Linux 2 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:ruby3.2 | [al-lambda/x86\$164/ruby 3.2](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/ruby3.2) | 
| Amazon Linux 2023 | aws/codebuild/amazonlinux-x86\$164-lambda-standard:ruby3.4 | [al-lambda/x86\$164/ruby 3.4](https://github.com/aws/aws-codebuild-docker-images/tree/master/al-lambda/x86_64/ruby3.4) | 

# 已弃用的图片 CodeBuild
<a name="deprecated-images"></a>

*已弃用的图像*是指不再由 CodeBuild缓存或更新的图像。弃用的映像不再接收次要版本更新或补丁版本更新，而且由于它们不再更新，因此使用它们可能不安全。如果您的 CodeBuild 项目配置为使用较旧的映像版本，则配置过程将下载此 docker 镜像并使用它来创建容器化运行时环境，这可能会延长配置持续时间和总体构建时长。

CodeBuild 已弃用以下 Docker 镜像。您仍然可以使用这些映像，但它们不会缓存在构建主机上，因此会导致预置时间更长。


| 平台 | 映像标识符 | 定义 | 弃用日期 | 
| --- | --- | --- | --- | 
| Amazon Linux 2 | aws/codebuild/amazonlinux2-x86\$164-standard:3.0 | al2/standard/3.0 | 2023 年 5 月 9 日 | 
| Ubuntu 18.04 | aws/codebuild/standard:4.0 | ubuntu/standard/4.0 | 2023 年 3 月 31 日 | 
| Amazon Linux 2 | aws/codebuild/amazonlinux2-aarch64-standard:1.0 | al2/aarch64/standard/1.0 | 2023 年 3 月 31 日 | 
| Ubuntu 18.04 | aws/codebuild/standard:3.0 | ubuntu/standard/3.0 | 2022 年 6 月 30 日 | 
| Amazon Linux 2 | aws/codebuild/amazonlinux2-x86\$164-standard:2.0 | al2/standard/2.0 | 2022 年 6 月 30 日 | 

**Topics**
+ [获取当前 Docker 映像的列表](build-env-ref-available-get.md)
+ [EC2 计算映像](ec2-compute-images.md)
+ [Lambda 计算映像](lambda-compute-images.md)
+ [已弃用的图片 CodeBuild](deprecated-images.md)
+ [可用的运行时](available-runtimes.md)
+ [运行时版本](runtime-versions.md)

# 可用的运行时
<a name="available-runtimes"></a>

您可以在 buildspec 文件的 `runtime-versions` 部分中指定一个或多个运行时。如果您的运行时依赖于另一个运行时，您还可以在 buildspec 文件中指定其依赖运行时。如果您未在 buildspec 文件中指定任何运行时，请 CodeBuild 选择您使用的映像中可用的默认运行时。如果指定一个或多个运行时，则仅 CodeBuild 使用这些运行时。如果未指定依赖运行时，则 CodeBuild 会尝试为您选择依赖运行时。

**注意**  
如果未指定运行时版本，则 CodeBuild 使用默认版本。当先前的默认版本达到使用寿命终止 (EOL) 时，默认版本可能会发生变化。为避免对构建环境进行意外更改，我们建议在 buildspec 文件中指定运行时版本。

 有关更多信息，请参阅 [Specify runtime versions in the buildspec file](build-spec-ref.md#runtime-versions-buildspec-file)。

[Specify runtime versions in the buildspec file](build-spec-ref.md#runtime-versions-buildspec-file).

.

**Topics**
+ [Linux 映像运行时](#linux-runtimes)
+ [macOS 映像运行时](#macOS-runtimes)
+ [Windows 映像运行时](#windows-runtimes)

## Linux 映像运行时
<a name="linux-runtimes"></a>

下表包含可用的运行时和支持这些运行时的标准 Linux 映像。


**Ubuntu 和 Amazon Linux 平台运行时系统**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/available-runtimes.html)

## macOS 映像运行时
<a name="macOS-runtimes"></a>

**重要**  
Mac 版本的 CodeBuild 精选映像包含预装的 macOS 和 Xcode。使用 Xcode 软件，即表示您承认、理解并同意 [Xcode 和 Apple SDKs 协议](https://www.apple.com/legal/sla/docs/xcode.pdf)。如果您不接受协议的条款和条件，请不要使用 Xcode 软件。请改为提供您自己的亚马逊机器映像（AMI）。有关更多信息，请参阅 [如何配置 macOS 预留容量实例集？](fleets.md#fleets.configure-macos)。

下表包含 macOS 支持的可用运行时。


**macOS 平台运行时**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/available-runtimes.html)

## Windows 映像运行时
<a name="windows-runtimes"></a>

Windows Server Core 2019 的基本映像包含以下运行时。


**Windows 平台运行时**  

| 运行时名称 | Windows Server Core 2019 标准版：1.0 版本 | Windows Server Core 2019 标准版：2.0 版本 | Windows Server Core 2019 标准版：3.0 版本 | 
| --- | --- | --- | --- | 
| dotnet | 3.15.0 | 3.16.07.0 | 8.0 | 
| dotnet sdk | 3.15.0 | 3.16.07.0 | 8.0 | 
| golang | 1.14 | 1.18 | 1.211.221.23 | 
| gradle | 6.7 | 7.6 | 8.12 | 
| java | Corretto11 | Corretto11Corretto17 | Corretto8Corretto11Corretto17Corretto21 | 
| maven | 3.6 | 3.8 | 3.9 | 
| nodejs | 14.15 | 16.19 | 20.1822.13 | 
| php | 7.4 | 8.1 | 8.38.4 | 
| PowerShell | 7.1 | 7.2 | 7.4 | 
| python | 3.8 | 3.10 | 3.103.113.123.13 | 
| ruby | 2.7 | 3.1 | 3.23.33.4 | 

# 运行时版本
<a name="runtime-versions"></a>

在 buildspec 文件的 [`runtime-versions`](build-spec-ref.md#build-spec.phases.install.runtime-versions) 部分中指定运行时期间，可以指定特定版本、特定主要版本和最新次要版本或最新版本。下表列出了可用的运行时及其指定方式。并非所有运行时版本都适用于所有映像。自定义镜像也不支持运行时版本选择。有关更多信息，请参阅 [可用的运行时](available-runtimes.md)。如果您想安装和使用自定义运行时版本，而不是预安装的运行时版本，请参阅[自定义运行时版本](#custom-runtime)。


**Ubuntu 和 Amazon Linux 2 平台运行时版本**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/runtime-versions.html)

在构建阶段，您可以使用编译规范来安装其他组件（例如，Apache Maven、Apache Ant、Mocha 或类似组件）。 AWS CLI RSpec `install`有关更多信息，请参阅 [buildspec 示例](build-spec-ref.md#build-spec-ref-example)。

## 自定义运行时版本
<a name="custom-runtime"></a>

您可以安装和使用自己选择的自定义版本，而不必在 CodeBuild托管映像中使用预安装的运行时版本。下表列出了可用的自定义运行时及其指定方式。

**注意**  
只有 Ubuntu 和 Amazon Linux 镜像才支持自定义运行时版本选择。


**自定义运行时版本**  

| 运行时名称  | 语法 | 示例 | 
| --- | --- | --- | 
| dotnet |  `<major>.<minor>.<patch>`  |  `5.0.408`  | 
| golang |  `<major>.<minor>` `<major>.<minor>.<patch>`  |  `1.19` `1.19.1`  | 
| java |  `corretto<major>`  |  `corretto15`  | 
| nodejs |  `<major>` `<major>.<minor>` `<major>.<minor>.<patch>`  |  `14` `14.21` `14.21.3`  | 
| php |  `<major>.<minor>.<patch>`  |  `8.0.30`  | 
| python |  `<major>` `<major>.<minor>` `<major>.<minor>.<patch>`  |  `3` `3.7` `3.7.16`  | 
| ruby |  `<major>.<minor>.<patch>`  |  `3.0.6`  | 

### 自定义运行时 buildspec 示例
<a name="custom-runtime-buildspec"></a>

以下是指定自定义运行时版本的 buildspec 示例。

```
version: 0.2
phases:
  install:
    runtime-versions:
      java: corretto15
      php: 8.0.30
      ruby: 3.0.6
      golang: 1.19
      python: 3.7
      nodejs: 14
      dotnet: 5.0.408
```