Docker 注册表 2.0 API v2

Docker registry 2.0 API v2

我拉取并设置了本地 docker registry:2.0

我曾尝试成功推送图片,但每当我尝试搜索图片时,我都会收到 404:

root@ip-10-232-0-153:~# curl -v -X GET http://localhost:5000/v2/search
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET /v2/search HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:5000
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Fri, 08 May 2015 00:00:45 GMT
< Content-Length: 19
<
404 page not found
* Connection #0 to host localhost left intact

另外,当我尝试卷曲 localhost:5000 时,我只得到一个 404:

404 page not found

更新(2016 年 4 月 14 日):仍然不在 distribution roadmap, but here is a particular issue about search.

更新(2015 年 11 月 12 日):API 端点仍然不存在,并且尚未在 Docker 注册表路线图中。

这里的问题是 new v2 Docker registry doesn't support that particular endpoint yet, as of this question and answer. You can check the source itself for the route endpoints, and you'll see that most of the API endpoints involve simple operations like uploading and tagging, but no implementation yet of the search endpoint. It's important here to note that the v2 registry is a completely different project than the v1 registry. It's even written in a completely different language (v1 was a Python project, whereas v2 uses Go, which is more in line with the rest of the Docker projects). It took me some time and serious reading to understand the dichotomy here between the registries. It is worth looking at this particular Github issue about the v2 registry 深入探讨了最近关于 v2 注册表状态的讨论,以及一些关于他们将其带到何处的讨论。

所以 v2 注册表中还没有搜索端点。您可以按标签或按任务编号 8 in this documentation.

中提到的图像名称本身列出您的图像

可从 https://github.com/docker/distribution 获得的最新版本 Docker 注册表支持目录 API。 (v2/_catalog)。这允许搜索功能。

如果有兴趣,您可以尝试 docker 我构建的图像注册表 CLI,以便在新的 Docker Registry v2 发行版中轻松使用搜索功能:(https://github.com/vivekjuneja/docker_registry_cli)

如果您使用的是 windows,这里有一个 Powershell 脚本,用于使用基本的 http 身份验证从 windows 查询 v2/_catalog

https://gist.github.com/so0k/b59382ea7fd959cf7040

仅供参考,要使用它,您必须 docker pull distribution/registry:master 而不是 docker pull registry:2registry:2 映像版本当前为 2.0.1,目录端点不附带。

在 Linux (Centos 7) 上,只要注册表映像是唯一容器,我就使用它 运行ning:这将列出推送到 resistry/container 的所有映像。 我把它放在一个脚本中并调整了剪切参数以获得我想要的,因为图像名称的长度确实有所不同。 运行 作为 sudo "script-name.sh"

grep -r -o "vars\.name=.* vars.reference=.*" /var/lib/docker/containers/* | cut -c 167-220 | sed 's/ver.*$//' | sed 's/vars\.name=//' | sed 's/ vars\.reference=/:/' | sort -u

正确。

这只是一个用于获取一些图像列表的实现示例。是的,假设这是一个通用的 registry2.0 启动。例如 $ sudo docker 运行 --name=myregistry -d -p port:port myregistry:1.0.

基本上每个容器都有一个日志文件...some-path/containers...ID-json.log。在该文件中存储有关推送到 运行ning 注册表的图像的信息。所以它可以用来推断图像列表。尽管它是原始的,但总比没有好。不是解决更大的 search/catalog 问题的方法,而是获取图像列表的方法。在等待 "official" 修复时解决问题是一种非常定制的解决方法。

Docker 在撰写本文时不支持注册表搜索功能 v2。 请参阅自 2015 年 2 月以来的讨论:https://github.com/docker/distribution/issues/206

Registry V2 就像把图片丢进一个黑色的包里,希望你记住你丢进去的是什么,你给图片起的名字。甚至不要考虑删除图像。我不想用 V1 替换 V2;尽管 V1 可以工作并且有几个工具可以与 V1 一起使用,包括搜索和删除。我从市场营销的注册表 V2 开始;更好的安全性和性能。

Ubuntu 14.04.3 LTS,CoreOS 723.3.0 注册表 github.com/docker/distribution v2.1.1

我写了一个名为 view-private-registry 的脚本来搜索注册表 V2 REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY。它适用于我的任何安装了 REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY 的系统。请告诉我您要进行的任何更改,谢谢。

脚本: https://github.com/BradleyA/Search-docker-registry-v2-script.1.0

#!/bin/bash
# %W% %G% %U%
#
#       View private registry,
#               if REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY is mounted on your system
#
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY="/mnt/three/docker-registry/registry-data"
#
find $REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY -print | \
    grep 'v2/repositories' | \
    grep 'current' | \
    grep -v 'link' | \
    sed -e 's/\/_manifests\/tags\//:/' | \
    sed -e 's/\/current//' | \
    sed -e 's/^.*repositories\//    /' | \
    sort > /tmp/a1
cat /tmp/a1
wc -l /tmp/a1 > /tmp/a2
echo "Number of images: `cat /tmp/a2 | awk {'print '}`"
echo "Disk space used:  `du -hs $REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY`"
rm /tmp/a1 /tmp/a2`

输出:

`$ ./view-private-registry`
busybox:latest
gcr.io/google_containers/etcd:2.0.9
gcr.io/google_containers/hyperkube:v0.21.2
gcr.io/google_containers/pause:0.8.0
google/cadvisor:latest
jenkins:latest
logstash:latest
mongo:latest
nginx:latest
python:2.7
redis:latest
registry:2.1.1
stackengine/controller:latest
tomcat:7
tomcat:latest
ubuntu:14.04.2
Number of images:   16
Disk space used:    1.7G    /mnt/three/docker-registry/registry-data

今天我尝试了 registry:master 图片,但不存在。

xotl@xotl-VM:~$ docker run registry:master
Unable to find image 'registry:master' locally
Pulling repository docker.io/library/registry
Tag master not found in repository docker.io/library/registry
xotl@xotl-VM:~$ 

现在您可以 运行 registry:2 并且将拥有端点。

如果我在我的机器上访问 http://localhost:5000/v2/_catalog,我可以看到这个输出 {"repositories":["ubuntu"]},这是正确的。还尝试了 http://localhost:5000/v2/ubuntu/tags/list 并得到了这个响应 {"name":"ubuntu","tags":["latest"]},所以它有效。

你可以a look at the docs.

@Xotl
curl -X GET registry.com:5000/v2/lashou/centos/tags/list
{"errors":[{"code":"NAME_UNKNOWN","message":"repository name not known to registry","detail":{"name":"lashou/centos"}}]}

我想检查 docker 图像是否存在的最简单方法是使用 Docker V2 REST API Tags list service

示例:-

curl $CURLOPTS -H "Authorization: Bearer $token" "https://hub.docker.com:4443/v2/your-repo-name/tags/list"

如果上面的结果 returns 200Ok 带有图像标签列表,那么我们知道该图像存在

{"name":"your-repo-name","tags":["1.0.0.1533677221","1.0.0.1533740305","1.0.0.1535659921","1.0.0.1535665433","latest"]}

否则,如果您看到类似

的内容
{"errors":[{"code":"NAME_UNKNOWN","message":"repository name not known to registry","detail":{"name":"your-repo-name"}}]} 

那么你肯定知道该图像不存在。