企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Container Registry API > 原文:[https://docs.gitlab.com/ee/api/container_registry.html](https://docs.gitlab.com/ee/api/container_registry.html) * [List registry repositories](#list-registry-repositories) * [Within a project](#within-a-project) * [Within a group](#within-a-group) * [Delete registry repository](#delete-registry-repository) * [List registry repository tags](#list-registry-repository-tags) * [Within a project](#within-a-project-1) * [Get details of a registry repository tag](#get-details-of-a-registry-repository-tag) * [Delete a registry repository tag](#delete-a-registry-repository-tag) * [Delete registry repository tags in bulk](#delete-registry-repository-tags-in-bulk) # Container Registry API[](#container-registry-api "Permalink") 在 GitLab 11.8 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/55978) . 这是[GitLab 容器注册表](../user/packages/container_registry/index.html)的 API 文档. ## List registry repositories[](#list-registry-repositories "Permalink") ### Within a project[](#within-a-project "Permalink") 获取项目中的注册表存储库列表. ``` GET /projects/:id/registry/repositories ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户可以访问[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `tags` | boolean | no | 如果参数包含为 true,则每个存储库在响应中都将包含一个`"tags"`数组. | | `name` | string | no | 返回名称与值匹配的存储库列表. (在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29763) ). | | `tags_count` | boolean | no | 如果参数包含为 true,则每个存储库的响应中都将包含`"tags_count"` (在 GitLab 13.1 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/32141) ). | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories" ``` 响应示例: ``` [ { "id": 1, "name": "", "path": "group/project", "project_id": 9, "location": "gitlab.example.com:5000/group/project", "created_at": "2019-01-10T13:38:57.391Z" }, { "id": 2, "name": "releases", "path": "group/project/releases", "project_id": 9, "location": "gitlab.example.com:5000/group/project/releases", "created_at": "2019-01-10T13:39:08.229Z" } ] ``` ### Within a group[](#within-a-group "Permalink") 获取组中的注册表存储库列表. ``` GET /groups/:id/registry/repositories ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户可以访问[的组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `tags` | boolean | no | 如果参数包含为 true,则每个存储库在响应中都将包含一个`"tags"`数组. | | `name` | string | no | 返回名称与值匹配的存储库列表. (在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29763) ). | | `tags_count` | boolean | no | 如果参数包含为 true,则每个存储库的响应中都将包含`"tags_count"` (在 GitLab 13.1 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/32141) ). | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/2/registry/repositories?tags=1&tags_count=true" ``` 响应示例: ``` [ { "id": 1, "name": "", "path": "group/project", "project_id": 9, "location": "gitlab.example.com:5000/group/project", "created_at": "2019-01-10T13:38:57.391Z", "tags_count": 1, "tags": [ { "name": "0.0.1", "path": "group/project:0.0.1", "location": "gitlab.example.com:5000/group/project:0.0.1" } ] }, { "id": 2, "name": "", "path": "group/other_project", "project_id": 11, "location": "gitlab.example.com:5000/group/other_project", "created_at": "2019-01-10T13:39:08.229Z", "tags_count": 3, "tags": [ { "name": "0.0.1", "path": "group/other_project:0.0.1", "location": "gitlab.example.com:5000/group/other_project:0.0.1" }, { "name": "0.0.2", "path": "group/other_project:0.0.2", "location": "gitlab.example.com:5000/group/other_project:0.0.2" }, { "name": "latest", "path": "group/other_project:latest", "location": "gitlab.example.com:5000/group/other_project:latest" } ] } ] ``` ## Delete registry repository[](#delete-registry-repository "Permalink") 删除注册表中的存储库. 该操作是异步执行的,可能要花一些时间才能执行. ``` DELETE /projects/:id/registry/repositories/:repository_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.html#namespaced-path-encoding) owned by the authenticated user. | | `repository_id` | integer | yes | 注册表存储库的标识. | ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2" ``` ## List registry repository tags[](#list-registry-repository-tags "Permalink") ### Within a project[](#within-a-project-1 "Permalink") 获取给定注册表存储库的标签列表. ``` GET /projects/:id/registry/repositories/:repository_id/tags ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户可以访问[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `repository_id` | integer | yes | 注册表存储库的标识. | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" ``` 响应示例: ``` [ { "name": "A", "path": "group/project:A", "location": "gitlab.example.com:5000/group/project:A" }, { "name": "latest", "path": "group/project:latest", "location": "gitlab.example.com:5000/group/project:latest" } ] ``` ## Get details of a registry repository tag[](#get-details-of-a-registry-repository-tag "Permalink") 获取注册表存储库标签的详细信息. ``` GET /projects/:id/registry/repositories/:repository_id/tags/:tag_name ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户可以访问[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `repository_id` | integer | yes | 注册表存储库的标识. | | `tag_name` | string | yes | 标签名称. | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags/v10.0.0" ``` 响应示例: ``` { "name": "v10.0.0", "path": "group/project:latest", "location": "gitlab.example.com:5000/group/project:latest", "revision": "e9ed9d87c881d8c2fd3a31b41904d01ba0b836e7fd15240d774d811a1c248181", "short_revision": "e9ed9d87c", "digest": "sha256:c3490dcf10ffb6530c1303522a1405dfaf7daecd8f38d3e6a1ba19ea1f8a1751", "created_at": "2019-01-06T16:49:51.272+00:00", "total_size": 350224384 } ``` ## Delete a registry repository tag[](#delete-a-registry-repository-tag "Permalink") 删除注册表存储库标记. ``` DELETE /projects/:id/registry/repositories/:repository_id/tags/:tag_name ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 认证用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `repository_id` | integer | yes | 注册表存储库的标识. | | `tag_name` | string | yes | 标签名称. | ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags/v10.0.0" ``` 此操作不会删除 Blob. 为了删除它们并回收磁盘空间,请[运行垃圾回收](https://docs.gitlab.com/omnibus/maintenance/README.html) . ## Delete registry repository tags in bulk[](#delete-registry-repository-tags-in-bulk "Permalink") 根据给定的标准批量删除注册表存储库标签. 有关概述,请参阅[利用 Container Registry API 删除除*之外的所有标签](https://youtu.be/Hi19bKe_xsg) . ``` DELETE /projects/:id/registry/repositories/:repository_id/tags ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 认证用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `repository_id` | integer | yes | 注册表存储库的标识. | | `name_regex` | string | no | 要删除的名称的[re2](https://github.com/google/re2/wiki/Syntax)正则表达式. 要删除所有标签,请指定`.*` . **注意:**不建议使用`name_regex`而建议使用`name_regex_delete` . 此字段已验证. | | `name_regex_delete` | string | yes | 要删除的名称的[re2](https://github.com/google/re2/wiki/Syntax)正则表达式. 要删除所有标签,请指定`.*` . 此字段已验证. | | `name_regex_keep` | string | no | 要保留名称的[re2](https://github.com/google/re2/wiki/Syntax)正则表达式. 此值将覆盖`name_regex_delete`所有匹配`name_regex_delete` . 此字段已验证. 注意:设置为`.*`将导致无操作. | | `keep_n` | integer | no | 要保留的给定名称的最新标签的数量. | | `older_than` | string | no | 早于给定时间的要删除的标签,以人类可读的格式`1h` , `1d` , `1month`编写. | 此 API 调用执行以下操作: 1. 它按创建日期排序所有标签. 创建日期是清单创建的时间,而不是标签推送的时间. 2. 它仅删除与给定`name_regex_delete` (或不`name_regex`使用的`name_regex` )匹配的标签,并保留所有与`name_regex_keep`匹配的`name_regex_keep` . 3. 它绝不会取消对标签命名`latest` . 4. 它保留 N 个最新的匹配标签(如果指定了`keep_n` ). 5. 它仅删除时间超过 X 时间的标签(如果指定了`older_than` ). 6. 它安排异步作业在后台执行. 这些操作是异步执行的,可能要花一些时间才能执行. 对于给定的容器存储库,您最多可以每小时运行一次. 此操作不会删除 Blob. 为了删除它们并回收磁盘空间,请[运行垃圾回收](https://docs.gitlab.com/omnibus/maintenance/README.html) . **注意:**从 GitLab 12.4 开始,将删除各个标签. 有关更多详细信息,请参见[讨论](https://gitlab.com/gitlab-org/gitlab/-/issues/15737) . Examples: 1. 删除与正则表达式(Git SHA)匹配的标记名,始终至少保留 5 个,并删除 2 天以上的标记名: ``` curl --request DELETE --data 'name_regex_delete=[0-9a-z]{40}' --data 'keep_n=5' --data 'older_than=2d' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" ``` 2. 删除所有标签,但始终保留最新的 5 个标签: ``` curl --request DELETE --data 'name_regex_delete=.*' --data 'keep_n=5' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" ``` 3. 删除所有标签,但始终保留以`stable`开头的标签: ``` curl --request DELETE --data 'name_regex_delete=.*' --data 'name_regex_keep=stable.*' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" ``` 4. 删除所有超过 1 个月的标签: ``` curl --request DELETE --data 'name_regex_delete=.*' --data 'older_than=1month' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" ```