Last active
May 29, 2018 06:14
-
-
Save luuil/2216b7c9e63bf24af4c4b77816ef7941 to your computer and use it in GitHub Desktop.
List docker images for a given registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding:utf-8 | |
''' | |
Created on 2018-05-02 | |
@author: [email protected] | |
@desc: List images name from registry | |
''' | |
from __future__ import print_function | |
import requests | |
import json | |
import traceback | |
def get_images_name(repo_ip,repo_port): | |
docker_images = [] | |
try: | |
url = "http://{repo_ip}:{repo_port}/v2/_catalog".format(repo_ip=repo_ip, repo_port=str(repo_port)) | |
res =requests.get(url).content.strip() | |
res_dic = json.loads(res) | |
images_type = res_dic['repositories'] | |
for i in images_type: | |
url2 = "http://{repo_ip}:{repo_port}/v2/{repo_id}/tags/list".format(repo_ip=repo_ip, | |
repo_port=str(repo_port), | |
repo_id=str(i)) | |
res2 =requests.get(url2).content.strip() | |
res_dic2 = json.loads(res2) | |
name = res_dic2['name'] | |
tags = res_dic2['tags'] | |
for tag in tags: | |
docker_name = "{repo_ip}:{repo_port}/{repo_name}:{repo_tag}".format(repo_ip=repo_ip, | |
repo_port=str(repo_port), | |
repo_name=name, | |
repo_tag=tag) | |
docker_images.append(docker_name) | |
print(docker_name) | |
except: | |
traceback.print_exc() | |
return docker_images | |
if __name__ == '__main__': | |
repo_ip = 'your/repo/ip' | |
repo_port = 5000 | |
images = get_images_name(repo_ip, repo_port) | |
print('Images count: {}'.format(len(images))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment