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
二、私有倉庫使用:
<font color="blue">上傳(兩步)</font>
第一步,打标簽(本地任意鏡像,打一個标簽,我這裡用 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 , 這裡隻是舉個例子。
<font color="blue">下載下傳</font>
** 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