主頁 > 知識庫 > Docker私有倉庫Registry部署的實(shí)現(xiàn)

Docker私有倉庫Registry部署的實(shí)現(xiàn)

熱門標(biāo)簽:企業(yè)400電話辦理哪正規(guī) 地圖標(biāo)注需要現(xiàn)場嗎 400電話辦理哪家好廠商 工廠位置地圖標(biāo)注 網(wǎng)站上插入地圖標(biāo)注內(nèi)容 鶴壁電銷外呼系統(tǒng)怎么安裝 地圖標(biāo)注企業(yè)名稱侵權(quán)案件 重慶營銷外呼系統(tǒng)排名 繽客網(wǎng)注冊時地圖標(biāo)注出不來

隨著docker使用的鏡像越來越多,就需要有一個保存鏡像的地方,這就是倉庫。目前常用的兩種倉庫:公共倉庫和私有倉庫。最方便的就是使用公共倉庫上傳和下載,下載公共倉庫的鏡像是不需要注冊的,但是上傳時,是需要注冊的。

私有倉庫最常用的就是Registry、Harbor兩種,那接下來詳細(xì)介紹如何搭建registry私有倉庫,Harbor將在下一篇博文部署。

一、部署Registry私有倉庫

案例描述

兩臺CentOS7.4,一臺為Docker私有倉庫;另一臺為Docker客戶端,測試使用;

兩臺服務(wù)器都需要安裝Docker服務(wù),請參考博文:安裝Docker.v19版本

1、配置registry私有倉庫

[root@centos01 ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf  
    <!--docker宿主機(jī)開啟路由功能-->
[root@centos01 ~]# sysctl -p  <!--刷新配置-->
net.ipv4.ip_forward = 1
[root@centos01 ~]# vim /etc/docker/daemon.json  <!--配置鏡像加速-->
{"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]}  <!--添加阿里云加速-->
[root@centos01 ~]# systemctl reload docker <!--重新啟動docker服務(wù)-->
[root@centos01 ~]# docker search registry <!--查找registry鏡像-->
<!--registry鏡像可以直接先pull下來,也可以不下載,根據(jù)自己情況而定-->
[root@centos01 ~]# docker run -d -p 5000:5000 --name registry --restart=always -v /opt/registry:/var/lib/registry registry
 <!--運(yùn)行registry容器,運(yùn)行registry服務(wù)存儲自己的鏡像-->
 <!--"--restart=always"參數(shù)是指此容器跟隨docker服務(wù)啟動而啟動-->
[root@centos01 ~]# docker ps  <!--查看docker運(yùn)行的容器-->
CONTAINER ID    IMAGE        COMMAND         CREATED       STATUS       PORTS          NAMES
a7773d77b8a3    registry      "/entrypoint.sh /etc…"  50 seconds ago   Up 46 seconds    0.0.0.0:5000->5000/tcp  registry
[root@centos01 ~]# docker images  <!--查看docker所有鏡像-->
REPOSITORY          TAG         IMAGE ID      CREATED       SIZE
registry           latest       708bc6af7e5e    3 months ago    25.8MB
tomcat            latest       1b6b1fe7261e    5 days ago     647MB
hub.c.163.com/public/centos  6.7-tools      b2ab0ed558bb    3 years ago     602MB
[root@centos01 ~]# vim /etc/docker/daemon.json <!--配置docker服務(wù)支持registry服務(wù)-->
{"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"],
"insecure-registries":["192.168.100.10:5000"]  <!--添加此行-->
}
[root@centos01 ~]# systemctl reload docker  <!--重新啟動docker服務(wù)-->

2、上傳鏡像到registry私有倉庫

[root@centos01 ~]# docker tag hub.c.163.com/public/centos:6.7-tools 192.168.100.10:5000/image/centos:6.7  
    <!--修改鏡像標(biāo)簽-->
[root@centos01 ~]# docker push 192.168.100.10:5000/image/centos:6.7 <!--上傳鏡像到registry私有倉庫-->

二、配置Docker客戶端訪問私有倉庫

<!--客戶端安裝docker服務(wù),配置鏡像加速-->
[root@centos02 ~]# vim /etc/docker/daemon.json  <!--配置docker支持registry服務(wù) -->
{"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"],
"insecure-registries":["192.168.100.10:5000"]  <!--添加此行-->
}
[root@centos02 ~]# systemctl restart docker  <!--重新啟動docker服務(wù)-->
[root@centos02 ~]# docker pull 192.168.100.10:5000/image/centos:6.7 
         <!--客戶端下載私有倉庫中的鏡像-->
[root@centos02 ~]# docker images <!--查看鏡像是否下載成功-->
REPOSITORY             TAG         IMAGE ID      CREATED       SIZE
192.168.100.10:5000/image/centos  6.7         b2ab0ed558bb    3 years ago     602MB

至此registry私有倉庫已經(jīng)搭建完成,但是現(xiàn)在存在一個問題,如果這也部署的話企業(yè)內(nèi)部所有人員皆可訪問我們的私有倉庫,為了安全起見,接下來為registry添加一個身份驗(yàn)證,只有通過了身份驗(yàn)證才可以上傳或者下載私有倉庫中的鏡像。

三、配置registry加載身份驗(yàn)證

[root@centos01 ~]# yum -y install httpd-tools  <!--安裝加密工具h(yuǎn)ttpd-tools-->
[root@centos01 ~]# mkdir /opt/registry-auth <!--創(chuàng)建存放驗(yàn)證密鑰目錄-->
[root@centos01 ~]# htpasswd -Bbn bob pwd@123 > /opt/registry-auth/htpasswd
 <!--配置registry身份驗(yàn)證數(shù)據(jù)庫-->
<!--"-Bbn”參數(shù)解釋:B強(qiáng)制密碼加密;b在命令中輸入密碼,不提示輸入密碼;n不更新密鑰文件-->

<!--刪除此服務(wù)器上的所有容器,接下來重新生成一個需要身份驗(yàn)證的私有倉庫容器-->
[root@centos01 ~]# docker run -d -p 5000:5000 --restart=always \

-v /opt/registry-auth/:/auth/ \

-v /opt/registry:/var/lib/registry --name registry-auth -e "REGISTRY_AUTH=htpasswd" \

-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \

-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry 
 <!--重新運(yùn)行一個支持身份驗(yàn)證的registry私有鏡像倉庫容器-->
[root@centos01 ~]# docker tag tomcat:latest 192.168.100.10:5000/image/tomcat:1.0 
    <!--鏡像修改標(biāo)簽-->
[root@centos01 ~]# docker push 192.168.100.10:5000/image/tomcat:1.0 
<!--測試不通過身份驗(yàn)證是否可以往私有倉庫上傳鏡像-->
no basic auth credentials
<!--提示沒有身份驗(yàn)證,上傳不了-->
[root@centos01 ~]# docker login 192.168.100.10:5000 
    <!--登錄私有鏡像倉庫,通過身份驗(yàn)證即可上傳-->
Username: bob   <!--輸入bob-->
Password:    <!--輸入密碼-->
……………… <!--此處省略部分內(nèi)容-->
Login Succeeded     <!--已通過身份驗(yàn)證,此時可以上傳鏡像到私有倉庫-->
[root@centos01 ~]# docker push 192.168.100.10:5000/image/tomcat:1.0 <!--再次上傳鏡像到私有倉庫-->
The push refers to repository [192.168.100.10:5000/image/tomcat]
b0ac242ce8d3: Pushed
5e71d8e4cd3d: Pushed
eb4497d7dab7: Pushed
bfbfe00b44fc: Pushed
d39111fb2602: Pushed
155d997ed77c: Pushed
88cfc2fcd059: Pushed
760e8d95cf58: Pushed
7cc1c2d7e744: Pushed
8c02234b8605: Pushed
1.0: digest: sha256:55b41e0290d32d6888aee2e9a15f03cc88d2f49d5ad68892c54b9527d0ed181c size: 2421
[root@centos02 ~]# docker pull 192.168.100.10:5000/image/tomcat:1.0 
 <!--docker客戶端不通過身份驗(yàn)證直接下載私有倉庫中的鏡像直接被拒絕-->
Error response from daemon: Get http://192.168.100.10:5000/v2/image/tomcat/manifests/1.0: no basic auth credentials
[root@centos02 ~]# docker login 192.168.100.10:5000 
    <!--登錄私有倉庫,通過身份驗(yàn)證-->
Username: bob  <!--輸入bob-->
Password:     <!--輸入密碼-->
Login Succeeded   <!--通過身份驗(yàn)證-->
[root@centos02 ~]# docker pull 192.168.100.10:5000/image/tomcat:1.0 <!--下載私有倉庫中的鏡像-->
1.0: Pulling from image/tomcat
376057ac6fa1: Pull complete
5a63a0a859d8: Pull complete
496548a8c952: Pull complete
2adae3950d4d: Pull complete
0a297eafb9ac: Pull complete
09a4142c5c9d: Pull complete
9e78d9befa39: Pull complete
18f492f90b9c: Pull complete
7834493ec6cd: Pull complete
216b2be21722: Pull complete
Digest: sha256:55b41e0290d32d6888aee2e9a15f03cc88d2f49d5ad68892c54b9527d0ed181c
Status: Downloaded newer image for 192.168.100.10:5000/image/tomcat:1.0
192.168.100.10:5000/image/tomcat:1.0
[root@centos02 ~]# docker images  <!--查看docker客戶端鏡像-->
REPOSITORY             TAG         IMAGE ID      CREATED       SIZE
192.168.100.10:5000/image/tomcat  1.0         1b6b1fe7261e    5 days ago     647MB
192.168.100.10:5000/image/centos  6.7         b2ab0ed558bb    3 years ago     602MB

到此這篇關(guān)于Docker私有倉庫Registry部署的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Docker私有倉庫Registry內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:東莞 96 渭南 鹽城 棗莊 克拉瑪依 日照 常州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Docker私有倉庫Registry部署的實(shí)現(xiàn)》,本文關(guān)鍵詞  Docker,私有,倉庫,Registry,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Docker私有倉庫Registry部署的實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Docker私有倉庫Registry部署的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章