由于公司之前是使用docker-registry存储镜像的。时间久了仓库就满了。于是需要写个脚本清理一下仓库
参考registry官方提供的api说明。整理脚本如下
import sys, os, json, httplib, urllib, base64, socket, commands, urllib2
if len(sys.argv) < 2:
print 'Please provide the repository name'
else:
retained_num = 3;
repsitory_domain = 'http://localhost:5000/v2'
print 'Try to check ', sys.argv[1]
image_name = sys.argv[1]
print "\nBegin to list all the docker images..."
print "Try to list images: %s/%s/tags" % (repsitory_domain, image_name)
request = urllib2.Request(url=repsitory_domain+'/'+image_name+'/tags/list')
request.add_header('Authorization','Basic cnVuc2RhdGE6UnVuc2RhdGEjZG9ja2Vya')
response = urllib2.urlopen(request)
#print response.headers
#status = response.headers['status']
body = response.read().decode('utf-8')
print body
#print status
if body ==