镜像标签可变性 - Amazon ECR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

镜像标签可变性

您可以将存储库配置为开启标签不变性,以防止覆盖映像标签。为存储库配置了不可变标签后,如果您尝试推送某个镜像但其标签在存储库中已存在,将返回 ImageTagAlreadyExistsException 错误。当存储库开启标签不可变性时,这会影响所有标签,您不能将某些标签配置为不可变,而将其他标签配置为可变。

使用 Amazon Web Services Management Console 和 Amazon CLI 工具,您可以在新存储库的创建期间或者随时为现有存储库设置镜像标签的可变性。对于控制台步骤,请参阅 创建私有存储库编辑私有存储库

创建配置有不可变标签的存储库

使用以下命令之一创建配置有不可变标签的新镜像存储库。

  • create-repository (Amazon CLI)

    aws ecr create-repository --repository-name name --image-tag-mutability IMMUTABLE --region us-east-2
  • New-ECRRepository (Amazon Tools for Windows PowerShell)

    New-ECRRepository -RepositoryName name -ImageTagMutability IMMUTABLE -Region us-east-2 -Force
更新现有存储库的镜像标签可变性设置

使用以下命令之一更新现有存储库的镜像标签可变性设置。

  • put-image-tag-mutability (Amazon CLI)

    aws ecr put-image-tag-mutability --repository-name name --image-tag-mutability IMMUTABLE --region us-east-2
  • Write-ECRImageTagMutability (Amazon Tools for Windows PowerShell)

    Write-ECRImageTagMutability -RepositoryName name -ImageTagMutability IMMUTABLE -Region us-east-2 -Force