How to list all tags of a docker image

http://www.googlinux.com/list-all-tags-of-docker-image/

Docker Search

To search a image on docker remote registry you can use docker search command.

Example:

root@googlinux.com:~# docker search ubuntu  
NAME  DESCRIPTION   STARS   OFFICIAL   AUTOMATED  
ubuntu   Ubuntu is a Debian-based Linux operating s...   4482   [OK]  
ubuntu-upstart   Upstart is an event-based replacement for ...   65   [OK]  
rastasheep/ubuntu-sshd   Dockerized SSH service, built on top of of...   32  [OK]  
torusware/speedus-ubuntu   Always updated official Ubuntu docker imag...   27   [OK]  

This example displays images with a name containing ubuntu. First column displays the name of image. You may notice rastasheep/ubuntu-sshd has a / in the name. The left portion i.e. rastasheep is the username and right portion i.e. ubuntu-sshd is the image name. Some image does not have a / in the name, just like the first one i.e. ubuntu. In this case library is the username

Note: Search queries will only return up to 25 results. You can use --limit option to change the search result display limit.

Docker pull

docker pull is the command to pull docker image from remote registry.

root@googlinux.com:~# docker pull debian  
Using default tag: latest  
latest: Pulling from library/debian  

This will try to pull the image with latest tag.

List first 10 tags

Listing all the available tag can be tricky. Well that information is always available on the image info page on hub.docker.com. There are lot of cases that you may need this information using a command line. This can be done using a simple API call and parsing the json output using jq tool.

root@googlinux.com:~# curl 'https://registry.hub.docker.com/v2/repositories/library/debian/tags/'|jq '."results"[]["name"]'  
"7.11"
"testing"
"oldstable-backports"
"oldstable"
"8"
"8.5"
"stretch"
"experimental"
"rc-buggy"
"wheezy-backports"

Note: jq is a tool for processing JSON inputs. jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

A script to List all Tags

i=0

while [ $? == 0 ]  
do  
   i=$((i+1))
   curl https://registry.hub.docker.com/v2/repositories/library/debian/tags/?page=$i 2>/dev/null|jq '."results"[]["name"]'

done  

and now debian image with a specific tag can be pulled using

root@googlinux.com:~# docker pull debian:testing  

Or if you want to pull all tag of a image

root@googlinux.com:~# docker pull -a debian  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值