Hello everyone. I am trying to get a list of docke...
# general
m
Hello everyone. I am trying to get a list of docker image tags and it seems the Docker API does not work properly with non-oficial images.
m
can you show the request you're attempting?
I am aware the request for an oficial image would be curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/REPONAME/tags?page_size=10'%7Cjq '.'
All the examples I found online (that works), are for oficial images, e.g. python,alpine.
V1 is deprecated. And V2 does not work (or at least I did not manage to get work)
m
the ref I see is structured differently than that
m
Let me have a look at it, Mike. Thanks for your help
m
good discussion on that question in general
m
Yeah, I saw that forum and others where users seem to mention the documentation is a bit vague.
I am testing with an image and now it can’t find the namespace, even though I can get the same namespace if I query the image with the command I sent above. 🥹
m
the example linked works for me
(using one of my own public images with anonymous auth)
m
What do you get when running curl -L -s 'https://hub.docker.com/v2/tags'
I think I know what it is going on….
m
what image are you inspecting for tags? If I look at
library/alpine
i see what I expect
If I look at
alpine/helm
I get that image's tags
this older format still seems to work, but you must present auth:
Copy code
"<https://registry-1.docker.io/v2/$item/tags/list>"
where item is
library/alpine
or
alpine/helm
m
When I checked the documentation, if not an official, you don’t add ‘llibrary’ to the url.
m
the
alpine
base image is official and under
library/alpine
the alpine based helm image is not, and so it's in the
alpine
namespace
m
So, if I want to get the tags for the image alpine/helm, I get the namespace does not exist.
m
it seems there are sort of 2 apis. docker hub api and regular registry api
the hub api requires namespace, while the registry api does not. my form above is the registry v2 api
m
Following the example of the documentation --. https://hub.docker.com/v2/namespaces/{namespace}/repositories/{repository}/images/{digest}/tags I would use --> https://hub.docker.com/v2/namespaces/alpine/repositories/helm/images/sha:/tags and get object not found","errinfo":{"namespace":"alpine","repository":"alpine"}}
Yes, I noticed the difference when using V2.
m
I'd think namespace:alpine repository:helm
interesting that the response thinks it's repo:alpine as well
m
V1 is not an option as credenciais won’t be available. V2 is not returning the tags 😅
m
this works just fine - v2 on the docker registry api
Copy code
docker_tags() {
  item="$1"
  case "$item" in
    */*):;; # namespace/image format
    *) item="library/$item";; # library image
  esac
  authUrl="<https://auth.docker.io/token?service=registry.docker.io&scope=repository:$item:pull>"
  token="$(curl -fsSL "$authUrl" | jq --raw-output '.token')"
  tagsUrl="<https://registry-1.docker.io/v2/$item/tags/list>"
  curl -fsSL -H "Accept: application/json" -H "Authorization: Bearer $token" "$tagsUrl" | jq '.tags[]'
}

docker_tags "$@"
step one grabs an auth token, step two hits the registry api to list tags. skips using the hub api
m
m
no,
/v2/
== v2
m
Sorry, I forgot to add the end of the url.
And yes, I had the answer in my question …
I will check the options. Once again, thanks for your assistance.