Docker registry 2.0 API v2

2019-01-17 07:29发布

I pulled and setup the local docker registry:2.0

I have tried pushing an image successfully, but when ever I try searching for an image I get 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

Also when I try to curl localhost:5000, I just get a 404:

404 page not found

9条回答
Evening l夕情丶
2楼-- · 2019-01-17 07:58

I guess the easiest way to check if a docker image is present is by using the Docker V2 REST API Tags list service

Example:-

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

if the above result returns 200Ok with a list of image tags, then we know that image exists

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

else if you see something like

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

then you know for sure that image doesn't exist.

查看更多
不美不萌又怎样
3楼-- · 2019-01-17 07:58
@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"}}]}
查看更多
▲ chillily
4楼-- · 2019-01-17 08:04

Correct.

It is simply an example of an implementation that works to obtain some list of images. Yes it is assumed this is a generic registry2.0 startup. for example $ sudo docker run --name=myregistry -d -p port:port myregistry:1.0.

Basically the point is each container has a log file ...some-path/containers... ID-json.log. In that file information is stored about images pushed to the running registry. So it can be used to extrapolate an image list. As raw as it is it is better than nothing. Not a solution to the bigger search/catalog issue but a way to get an image list. It is a very customized workaround to solve a problem while waiting for the "official" fix.

查看更多
登录 后发表回答