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

前端 未结 10 1221
小蘑菇
小蘑菇 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:45

    When using CoreOS, jq is available to parse JSON data.

    So like you were doing before, looking at library/centos:

    $ curl -s -S 'https://registry.hub.docker.com/v2/repositories/library/centos/tags/' | jq '."results"[]["name"]' |sort
    "6"
    "6.7"
    "centos5"
    "centos5.11"
    "centos6"
    "centos6.6"
    "centos6.7"
    "centos7.0.1406"
    "centos7.1.1503"
    "latest"
    

    The cleaner v2 API is available now, and that's what I'm using in the example. I will build a simple script docker_remote_tags:

    #!/usr/bin/bash
    curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$@/tags/" | jq '."results"[]["name"]' |sort
    

    Enables:

    $ ./docker_remote_tags library/centos
    "6"
    "6.7"
    "centos5"
    "centos5.11"
    "centos6"
    "centos6.6"
    "centos6.7"
    "centos7.0.1406"
    "centos7.1.1503"
    "latest"
    

    Reference:

    jq: https://stedolan.github.io/jq/ | apt-get install jq

提交回复
热议问题