Skip to content

Instantly share code, notes, and snippets.

@ochinchina
Created November 7, 2016 05:35
Show Gist options
  • Save ochinchina/73322247513f18922a53339bbbfdafe1 to your computer and use it in GitHub Desktop.
Save ochinchina/73322247513f18922a53339bbbfdafe1 to your computer and use it in GitHub Desktop.
list tags by the image name in docker
#!/usr/bin/python2
import json
import urllib2
import sys
def get_tags( image):
tmp = image.split("/")
if len( tmp ) == 3:
f = urllib2.urlopen("https://%s/v2/%s/tags/list" % (tmp[0], tmp[1] + "/" + tmp[2] ) )
else:
f = urllib2.urlopen("https://registry.hub.docker.com/v1/repositories/%s/tags" % image )
try:
jsonData = json.loads( f.read() )
if type(jsonData) is list:
for data in jsonData:
print data["name"]
elif "tags" in jsonData:
for data in jsonData["tags"]:
print data
except:
print "not find %s" % image
get_tags( sys.argv[1] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment