技能 Azure Container Registry SDK for Python
📦

Azure Container Registry SDK for Python

安全

Azure Container Registry Python SDK

使用官方 Python SDK 管理 Azure Container Registry 中的容器镜像和制品。此技能提供可直接使用的代码示例,涵盖认证、仓库操作和制品管理。

支持: Claude Codex Code(CC)
🥉 73 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“Azure Container Registry SDK for Python”。 列出 ACR 中的仓库

预期结果:

```python
from azure.containerregistry import ContainerRegistryClient
from azure.identity import DefaultAzureCredential

client = ContainerRegistryClient(
endpoint="https://myregistry.azurecr.io",
credential=DefaultAzureCredential()
)

for repository in client.list_repository_names():
print(repository)
```

正在使用“Azure Container Registry SDK for Python”。 清理旧镜像

预期结果:

```python
from datetime import datetime, timedelta, timezone

cutoff = datetime.now(timezone.utc) - timedelta(days=30)

for manifest in client.list_manifest_properties("my-image"):
if manifest.last_updated_on < cutoff and not manifest.tags:
print(f"Deleting {manifest.digest}")
client.delete_manifest("my-image", manifest.digest)
```

安全审计

安全
v1 • 2/24/2026

This is a documentation-only skill containing reference material and code examples for the Azure Container Registry Python SDK. No executable code, scripts, or dangerous patterns were detected. The skill provides static reference content for SDK usage and presents no security risks.

0
已扫描文件
0
分析行数
0
发现项
1
审计总数
未发现安全问题
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
100
安全
83
规范符合性

你能构建什么

DevOps 工程师管理 CI/CD 流水线

作为部署工作流的一部分,在 ACR 中查询和管理容器镜像

开发人员使用容器镜像

列出仓库、检查镜像元数据并管理开发项目的标签

平台工程师维护仓库清洁

清理旧镜像并管理容器仓库的保留策略

试试这些提示

列出 ACR 中的仓库
如何使用 Python SDK 列出我的 Azure Container Registry 中的所有仓库?
使用 Entra ID 进行身份验证
展示如何使用 DefaultAzureCredential 在 Python 中对 Azure Container Registry 进行身份验证
按日期删除旧镜像
编写 Python 代码从 Azure Container Registry 中删除超过 30 天的容器镜像
下载清单和 Blob
如何使用 Python SDK 从 ACR 下载容器清单及其 Blob 层?

最佳实践

  • 在生产环境中使用 Entra ID(DefaultAzureCredential)进行身份验证,而不是存储凭据
  • 使用 can_delete=False 锁定生产镜像以防止意外删除
  • 按摘要而非按标签删除,以避免镜像孤立

避免

  • 在源代码中硬编码凭据而不是使用托管标识
  • 按标签删除镜像而不检查是否有其他标签指向相同摘要
  • 在高频操作场景中使用同步客户端,而异步客户端会更高效

常见问题

如何对 Azure Container Registry 进行身份验证?
生产环境请使用 DefaultAzureCredential。它会自动通过托管标识、服务主体或开发者凭据处理身份验证。
可以,通过设置 credential=None 并为公共仓库(如 mcr.microsoft.com)指定 audience 参数来使用匿名访问。
如何安全地删除旧镜像?
删除前检查 manifest.tags 以确保您不是在移除带标签的镜像。按摘要删除以避免镜像孤立。
同步客户端和异步客户端有什么区别?
异步客户端(aio)推荐用于高吞吐量操作。它们允许并发请求和更好的资源利用。
如何锁定镜像以防止删除?
使用 update_manifest_properties 或 update_repository_properties 并设置 can_delete=False 来锁定镜像或整个仓库。
此技能会创建 Azure 资源吗?
不,此技能仅提供管理现有 Azure Container Registry 的代码示例。您必须通过 Azure Portal 或 CLI 单独创建仓库。

开发者详情

文件结构

📄 SKILL.md