Python Docker 查看私有仓库镜像【转】

2020-10-15 14:40:20 浏览数 (1)

文章来源:python Docker 查看私有仓库镜像

pip 安装:

代码语言:javascript复制
# 首先安装epel扩展源:
yum -y install epel-release
# 更新完成之后,就可安装pip:
yum -y install python-pip
# 安装完成之后清除cache:
yum clean all

request模块安装:

代码语言:javascript复制
pip install request

get.py 脚本:

代码语言:javascript复制
 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 
 4 import requests  
 5 import json  
 6 import traceback  
 7    
 8 repo_ip = '192.168.0.153'  
 9 repo_port = 5000  
10    
11 def getImagesNames(repo_ip,repo_port):  
12     docker_images = []  
13     try:  
14         url = "http://"   repo_ip   ":"  str(repo_port)   "/v2/_catalog"  
15         res =requests.get(url).content.strip()  
16         res_dic = json.loads(res)  
17         images_type = res_dic['repositories']  
18         for i in images_type:  
19             url2 = "http://"   repo_ip   ":"  str(repo_port)  "/v2/"   str(i)   "/tags/list"  
20             res2 =requests.get(url2).content.strip()  
21             res_dic2 = json.loads(res2)  
22             name = res_dic2['name']  
23             tags = res_dic2['tags']  
24             for tag in tags:  
25                 docker_name = str(repo_ip)   ":"   str(repo_port)   "/"   name   ":"   tag  
26                 docker_images.append(docker_name)  
27                 print docker_name  
28     except:  
29         traceback.print_exc()  
30     return docker_images  
31    
32 a=getImagesNames(repo_ip, repo_port)  
33 #print a  

0 人点赞