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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.