#! /usr/bin/python3
import json
import urllib.request
urlhead = '10.128.222.245:5000/'
def getTag(image):
requrl = "http://"+urlhead+"/v2/"+image+"/tags/list"
webURL = urllib.request.urlopen(requrl)
#print(webURL.read())
#JSON_object = json.loads(webURL.read()) #this is the line that doesn't work
data = webURL.read()
#print(data)
encoding = webURL.info().get_content_charset('utf-8')
json_data = json.loads(data.decode(encoding))
#print(json_data)
print ( urlhead+ json_data['name']+ ':' + json_data['tags'][0])
requrl = "http://"+urlhead+"/v2/_catalog"
webURL = urllib.request.urlopen(requrl)
data = webURL.read()
#print(data)
encoding = webURL.info().get_content_charset('utf-8')
json_data = json.loads(data.decode(encoding))
#print(json_data)
#print(len(json_data['repositories']))
for element in json_data['repositories']:
#print(element)
getTag(element)

本文介绍了一个使用Python脚本查询Docker镜像及其标签列表的方法。通过发送HTTP请求到Docker仓库API,可以获取指定镜像的所有可用标签,并列出Docker仓库中的所有镜像名称。
30万+

被折叠的 条评论
为什么被折叠?



