hans

hans

【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

上面代碼找不到原作者文章了,

反正參考自: http://www.linuxidc.com/Linux/2017-02/140961.htm

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。