How can I list all tags for a Docker image on a remote registry?

前端 未结 19 1887
时光取名叫无心
时光取名叫无心 2020-12-04 04:46

How can I list all tags of a Docker image on a remote Docker registry using the CLI (preferred) or curl?

Preferably without pulling all versions from the remote regi

相关标签:
19条回答
  • 2020-12-04 05:11

    If folks want to read tags from the RedHat registry at https://registry.redhat.io/v2 then the steps are:

    # example nodejs-12 image
    IMAGE_STREAM=nodejs-12
    REDHAT_REGISTRY_API="https://registry.redhat.io/v2/rhel8/$IMAGE_STREAM"
    # Get an oAuth token based on a service account username and password https://access.redhat.com/articles/3560571
    TOKEN=$(curl --silent -u "$REGISTRY_USER":"$REGISTRY_PASSWORD" "https://sso.redhat.com/auth/realms/rhcc/protocol/redhat-docker-v2/auth?service=docker-registry&client_id=curl&scope=repository:rhel:pull" |  jq --raw-output '.token')
    # Grab the tags
    wget -q --header="Accept: application/json" --header="Authorization: Bearer $TOKEN" -O - "$REDHAT_REGISTRY_API/tags/list" | jq -r '."tags"[]' 
    

    If you want to compare what you have in your local openshift registry against what is in the upstream registry.redhat.com then here is a complete script.

    0 讨论(0)
  • 2020-12-04 05:12

    Building on Yan Foto's answer (the v2 api), I created a simple Python script to list the tags for a given image.

    Usage:

    ./docker-registry-list.py alpine
    

    Output:

    {
      "name": "library/alpine",
      "tags": [
        "2.6",
        "2.7",
        "3.1",
        "3.2",
        "3.3",
        "3.4",
        "3.5",
        "3.6",
        "3.7",
        "edge",
        "latest"
      ]
    }
    
    0 讨论(0)
  • 2020-12-04 05:13

    See CLI utility: https://www.npmjs.com/package/docker-browse

    Allows enumeration of tags and images.

    docker-browse tags <image> will list all tags for the image. e.g. docker-browse tags library/alpine

    docker-browse images will list all images in the registry. Not currently available for index.docker.io.

    You may connect it to any registry, including your private one, so long as it supports Docker Registry HTTP API V2

    0 讨论(0)
  • 2020-12-04 05:14

    As of Docker Registry V2, a simple GET suffice:

    GET /v2/<name>/tags/list
    

    See docs for more.

    0 讨论(0)
  • 2020-12-04 05:14

    If the JSON parsing tool, jq is available

    wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O - | \
        jq -r '.[].name'
    
    0 讨论(0)
  • 2020-12-04 05:15

    You can achieve by running on terminal this:

    curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/mysql/tags/' | jq . | grep name
    

    Also, if you don't have jq you have to install it by

    sudo apt-get install jq
    
    0 讨论(0)
提交回复
热议问题