How can I find a Docker image with a specific tag in Docker registry on the Docker command line?

前端 未结 10 1209
小蘑菇
小蘑菇 2020-12-12 18:21

I try to locate one specific tag for a Docker image. How can I do it on the command line? I want to avoid downloading all the images and then removing the unneeded ones.

10条回答
  •  半阙折子戏
    2020-12-12 18:41

    The v2 API seems to use some kind of pagination, so that it does not return all the available tags. This is clearly visible in projects such as python (or library/python). Even after quickly reading the documentation, I could not manage to work with the API correctly (maybe it is the wrong documentation).

    Then I rewrote the script using the v1 API, and it is still using jq:

    #!/bin/bash
    
    repo="$1"
    
    if [[ "${repo}" != */* ]]; then
        repo="library/${repo}"
    fi
    
    url="https://registry.hub.docker.com/v1/repositories/${repo}/tags"
    curl -s -S "${url}" | jq '.[]["name"]' | sed 's/^"\(.*\)"$/\1/' | sort
    

    The full script is available at: https://github.com/denilsonsa/small_scripts/blob/master/docker_remote_tags.sh

    I've also written an improved version (in Python) that aggregates tags that point to the same version: https://github.com/denilsonsa/small_scripts/blob/master/docker_remote_tags.py

提交回复
热议问题