问题
I'm trying to find some API (for example java, but could be some other) how to get published docker image names / tags from google cloud platform registry. I found how to do this using gcloud console commands:
gcloud container images list-tags gcr.io/[GCP_REPOSITORY_NAME]
And it basically gave what I want, but it is console and I need this data get programmatically on back-end side. Any ideas guys? Thanks in advance.
回答1:
Currently there is no REST API for the Google Container Registry product but you can use the Registry name as an URL and run an HTTP request within your Java code against it:
curl -u "oauth2accesstoken:yourAccessToken" https://gcr.io/v2/yourProject/yourImage/tags/list
You can get the accessToken
with the command gcloud auth print-access-token
. The recommend approach is that it belongs to a serviceAccount.
Although I am not sure if the Docker Registry HTTP API V2 is fully compatible with Google Container Registry, this specific method has worked for me.
来源:https://stackoverflow.com/questions/55059636/how-to-get-list-of-published-docker-images-from-gcp-registry-programmatically