问题
An external organization that I work with has given me access to a private (auth token protected) docker registry, and eventually I would like to be able to query this registry, using docker's HTTP API V2, in order to obtain a list of all the repositories and/or images available in the registry.
But before I do that, I'd first like to get some basic practice with constructing these types of API queries on a public registry such as Docker Hub. So I've gone ahead and registered myself with a username and password on Docker Hub, and also consulted the API V2 documentation, which states that one may request an API version check as:
GET /v2/
or request a list of repositories as:
GET /v2/_catalog
Using curl, together with the username and password that I used in order to register my Docker Hub account, I attempt to construct a GET request at the command line:
stachyra> curl -u stachyra:<my_password> -X GET https://index.docker.io/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}
stachyra> curl -u stachyra:<my_password> -X GET https://index.docker.io/v2/_catalog
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}
where of course, in place of <my_password>
, I substituted my actual account password.
The response that I had been expecting from this query was a giant json message, listing thousands of repository names, but instead it appears that the API is rejecting my Docker Hub credentials.
Question 1: Do I even have the correct URL (index.docker.io
) for the docker hub registry? (I made this assumption in the first place based upon the status information returned by the command line tool docker info
, so I have good reason to think it's correct.)
Question 2: Assuming I have the correct URL for the registry service itself, why does my query return an "UNAUTHORIZED" error code? My account credentials work just fine when I attempt to login via the web at hub.docker.com, so what's the difference between the two cases?
回答1:
This site says we cannot :(
Dockerhub hosts a mix of public and private repositories, but does not expose a catalog endpoint to programmatically list them.
来源:https://stackoverflow.com/questions/56193110/how-can-i-use-docker-registry-http-api-v2-to-obtain-a-list-of-all-repositories-i