溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

docker系列-搭建本地私有倉庫-registry容器的各種坑

發(fā)布時間:2020-06-17 02:11:59 來源:網(wǎng)絡(luò) 閱讀:800 作者:tutor 欄目:云計算

總結(jié)的坑:
a.關(guān)注daemon.json的書寫格式。一句話可以錯好幾個點。
b.tag要清楚的表示registry服務(wù)器的信息,才能push上傳成功。不是可有可無的信息。
c.tag中有版本號要清楚的寫上。系統(tǒng)自動補全的是用latest。

####################################################################

搭建過程:
前提:通過docker pull registry下載了registry

1.新建的/etc/docker/daemon.json
[root@master docker]# cat daemon.json
{
"insecure-registries": ["172.17.0.1:5000"]
}
下面這種報錯,是因為新建的/etc/docker/daemon.json文件還沒有成功。
[root@master ~]# docker push 172.17.0.1:5000/hello-world
The push refers to repository [172.17.0.1:5000/hello-world]
Get https://172.17.0.1:5000/v2/: http: server gave HTTP response to HTTPS client

容易出錯的4個地方:
a.錯誤的寫成 insecure-registry.
b.錯誤的寫成 http://172.17.0.1:5000
c.錯誤的用了容器的IP 172.17.0.2
d.忘記重啟docker服務(wù)
#########################################################################

2.本地是否建立成功registry,可以通過docker info 查看
[root@master docker]# docker info | grep -i -A 3 regis
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
172.17.0.1:5000
127.0.0.0/8
Live Restore Enabled: false
##########################################################################

3. 啟動本地registry容器,push上傳image到本地registry容器
mkdir -p /data/registry
##host上創(chuàng)建目錄volume給容器做存儲
docker run -d -p 5000:5000 -v /data/registry:/var/lib/registry --name local_registry registry
##啟動容器,對外用5000端口,第一個5000是host的端口,第二個5000是容器端口
[root@master docker]# docker ps | grep -i local_registry
b4c6b769aabc registry "/entrypoint.sh /etc…" About an hour ago Up 30 minutes 0.0.0.0:5000->5000/tcp local_registry
##檢查registry容器是否啟動

[root@master ~]# docker tag hello-world 172.17.0.1:5000/hello-world:v1
[root@master ~]# docker push 172.17.0.1:5000/hello-world:v1
The push refers to repository [172.17.0.1:5000/hello-world]
af0b15c8625b: Pushed
v1: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
[root@master ~]#

##注意:docker tag hello-world 172.17.0.1:5000/hello-world:v1 一定要打上正確的tag,也就是tag一定要清楚表示清楚是哪個registry。
不然,docker不知道是要將image上傳到哪個registry服務(wù)器。也就是說tag包含了registry服務(wù)器的信息,不是一個可有可無的東西。

##########################################################################

4.刪除host上有的images。測試從容器pull下來image。
注意:刪除或者上傳是如果有版本號不是latest,需要附加上。系統(tǒng)默認是自動補充latest,這樣執(zhí)行命令后反饋找不到

[root@master docker]# docker rmi 172.17.0.1:5000/hello-world
Error: No such image: 172.17.0.1:5000/hello-world
[root@master docker]# docker rmi 172.17.0.1:5000/hello-world:v1
Untagged: 172.17.0.1:5000/hello-world:v1
Untagged: 172.17.0.1:5000/hello-world@sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
[root@master docker]#

[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 3a2ef06682ac 9 hours ago 356MB
wordpress latest a541a1a59631 2 days ago 447MB
busybox latest e4db68de4ff2 2 weeks ago 1.22MB
registry.aliyuncs.com/google_containers/kube-proxy v1.14.0 5cd54e388aba 3 months ago 82.1MB
registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
registry latest f32a97de94e1 3 months ago 25.8MB
[root@master docker]#

[root@master docker]# docker pull 172.17.0.1:5000/hello-world
Using default tag: latest
Error response from daemon: manifest for 172.17.0.1:5000/hello-world:latest not found

[root@master docker]# docker pull 172.17.0.1:5000/hello-world:v1
v1: Pulling from hello-world
1b930d010525: Pull complete
Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
Status: Downloaded newer image for 172.17.0.1:5000/hello-world:v1
[root@master docker]#
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 3a2ef06682ac 9 hours ago 356MB
wordpress latest a541a1a59631 2 days ago 447MB
busybox latest e4db68de4ff2 2 weeks ago 1.22MB
registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
registry latest f32a97de94e1 3 months ago 25.8MB
172.17.0.1:5000/hello-world v1 fce289e99eb9 6 months ago 1.84kB
[root@master docker]#

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI