如何在docker registry v2中标记图像

时间:2016-05-10 09:50:38

标签: docker docker-registry

我们的CI-CD中有逻辑标记(通过REST)将图像分段到最新(如果测试成功)。这适用于注册表v1。

现在已转移到v2 api,我无法在文档中找到如何添加"标记到注册表中的现有图像。我在一个可以带来"清单"的步骤中。一些暂存图片,但不知道如何添加标签和http发布它。 试图发送以下输入

  1. " tag":" staging"," latest",

  2. " tag":[" staging"," latest"], 还有更多

    { " schemaVersion":1, " name":" configservice", "标记":" staging", " architecture":" amd64", " fsLayers":[....

4 个答案:

答案 0 :(得分:11)

如果您的Docker Registry支持清单架构版本2,则只需在新标记下上载现有图像的清单即可。

例如,假设您要标记最新版本的busybox图片。步骤将是:

下载现有的清单:

curl '<registry_url>/v2/mybusybox/manifests/latest' \
-H 'accept: application/vnd.docker.distribution.manifest.v2+json' \
> manifest.json

以下是清单的样子(请注意,schemaVersion为2):

{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/octet-stream",
      "size": 1459,
      "digest": "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749"
   },
   "layers": [
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 667590,
         "digest": "sha256:8ddc19f16526912237dd8af81971d5e4dd0587907234be2b83e249518d5b673f"
      }
   ]
}

在新标记下上传清单:

curl -XPUT '<registry_url>/v2/mybusybox/manifests/new_tag' \
-H 'content-type: application/vnd.docker.distribution.manifest.v2+json' \
-d '@manifest.json'

详细的分步指南将在此post中提供。

答案 1 :(得分:7)

这不是你问题的直接答案,但我总是做以下事情......

<jndiEntry jndiName="analytics/wl.analytics.logs.forward" value="true" />

答案 2 :(得分:1)

我只是想添加一下,因为这是在我的搜索结果中出现的,所以Google Container Registry包含a command可以直接执行此操作。

use warnings;
use strict;

use File::Find::Rule;
use File::Path qw/remove_tree/;

my $dir = ".";
my $mtime = time - 90 * 60 * 60 * 24;

my @things = File::Find::Rule->maxdepth(1)->mtime( "<= $mtime" )->in($dir);

for my $thing (@things) {
    next if $thing eq $dir;
    if ( -f $thing) {
        unlink $thing or warn "could not delete file $thing : $!";
    } else {
        remove_tree($thing);
    }
}

以上wheleph所描述的工作流程可以正常工作,但是导致创建了一个新容器,而不是在现有容器上应用了附加标签。

答案 3 :(得分:1)

This answer仅适用于更改图像标签,但是我也想更改存储库名称

感谢Nicholas Dille's 'How to tag docker images without pulling them' post,我也可以更改repoName!在his nicholasdille/PowerShell-RegistryDocker project项目的帮助下:

  1. 获取清单(在v2模式中)
  2. 将每个layer.digest发布到新的仓库中
  3. 发布config.layer
  4. 将整个清单输入新的仓库

详细信息:

    来自reg:5000/v2/{oldRepo}/manifests/{oldtag}且标题为accept
  1. GET 清单:application/vnd.docker.distribution.manifest.v2+json

  2. 对于每一层: POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={layer.digest}&from={oldRepoNameWithaoutTag}

  3. POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={config.digest}&from={oldRepoNameWithaoutTag}

  4. PUT reg:5000/v2/{newRepo}/manifests/{newTag},其标题为content-type:来自步骤1响应的application/vnd.docker.distribution.manifest.v2+jsonbody

  5. 享受!