1. 程式人生 > >【Docker】建立私有倉庫, 檢視私有倉庫映象, 方便本地共享

【Docker】建立私有倉庫, 檢視私有倉庫映象, 方便本地共享

網上教程真心很多, 但感覺亂七八糟的.

還是自己寫好, 以後再用也方便.

不多廢話了.

1. 拉取registry

sudo docker pull registry:2

2. 建立私有倉庫的容器

sudo docker run -d -p 5000:5000 registry:2

3. 新增驗證

sudo vim /etc/sysconfig/docker

other_args="--insecure-registry xxx.xxx.xxx.xxx:5000" 修改這一行,xxx是你電腦的IP地址

sudo /etc/init.d/docker restart

或者
sudo vim /etc/docker/daemon.json

開頭新增
{"insecure-registries":["xxx.xxx.xxx.xxx:5000"]}

sudo /etc/init.d/docer restart

區域網其他電腦上傳下載映象也需要做第三步才可以.

4. 獲取私有倉庫映象列表:

import requests
import json
import traceback
 
repo_ip = '10.100.4.20'
repo_port = 5000
 
def getImagesNames(repo_ip,repo_port):
    docker_images = []
    try:
        url = "http://" + repo_ip + ":" +str(repo_port) + "/v2/_catalog"
        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 + ":" +str(repo_port) +"/v2/" + str(i) + "/tags/list"
            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 = str(repo_ip) + ":" + str(repo_port) + "/" + name + ":" + tag
                docker_images.append(docker_name)
                print docker_name
    except:
        traceback.print_exc()
    return docker_images
 
a=getImagesNames(repo_ip, repo_port)
#print a
上面程式碼找不到原作者文章了,