Docker私有仓库搭建

Docker私有仓库搭建

一、制作镜像:(2步完成)

第一步:下载仓库镜像

docker pull registry

第二步:启动

docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

说明默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下。

私有仓库搭建完成。

详细日志如下:

[root@helloword ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
49388a8c9c86: Pull complete 
e4d43608dd22: Pull complete 
3a41740f900c: Pull complete 
e16ef4b76684: Pull complete 
65f212f7c778: Pull complete 
Digest: sha256:d837de65fd9bdb81d74055f1dc9cc9154ad5d8d5328f42f57f273000c402c76d
Status: Downloaded newer image for registry:latest
[root@helloword ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
d4ecd71b2c08b293504bb85c43d347c9e1e6cedda157e63586562d13b5a2655f

二、私有仓库使用:

上传(两步)

第一步,打标签(本地任意镜像,打一个标签,我这里用 hello-world)

docker pull hello-world
docker tag hello-world 127.0.0.1:5000/hello-world

第二步,push上去:

docker push 127.0.0.1:5000/hello-world

上传成功

简单说明:
如果是别的机器要上传,那么ip就要是本机的ip,不能使用127.0.0.1 , 这里只是举个例子。

下载

** pull下来:**

docker pull 127.0.0.1:5000/hello-world

详细日志:

[root@helloword ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:5cf8f274a86b7a22a853c8031b8da47a32135b6f266a2a6777c68483ab728679
Status: Downloaded newer image for hello-world:latest
[root@helloword ~]# docker tag hello-world 127.0.0.1:5000/hello-world
[root@helloword ~]# docker push 127.0.0.1:5000/hello-world
The push refers to a repository [127.0.0.1:5000/hello-world]
f999ae22f308: Pushed 
latest: digest: sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b size: 524
[root@helloword ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
127.0.0.1:5000/hello-world   latest              f2a91732366c        10 hours ago        1.85kB
hello-world                  latest              f2a91732366c        10 hours ago        1.85kB
[root@helloword ~]# docker rmi 127.0.0.1:5000/hello-world
Untagged: 127.0.0.1:5000/hello-world:latest
Untagged: 127.0.0.1:5000/hello-world@sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b
[root@helloword ~]# docker pull 127.0.0.1:5000/hello-world
Using default tag: latest
latest: Pulling from hello-world
Digest: sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b
Status: Downloaded newer image for 127.0.0.1:5000/hello-world:latest

如果有出现报错,可能是因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。
不同的系统,解决方式不一样,简单的百度一下即可。(TODO 后续补充)

三、私有仓库管理:(方式很多,这里介绍几种)

1)使用命令的方式查看镜像:ip可以变

[root@helloword ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["hello-world"]}

2)pyhton的方式查看:

#-*- coding:utf-8 -*-
#!/usr/local/bin/python python
'''
Created on 2017.07.08
@author: wzw
@desc: get images name from registry
'''
 
import requests
import json
import traceback
 
repo_ip = '47.96.2.146'
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

执行 python2 xxx.py
3)使用工具查看 Humpback
https://www.cnblogs.com/humin/p/6970212.html

你可能感兴趣的:(Docker私有仓库搭建)