人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

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

發(fā)布日期:2022-02-03 18:59 | 文章來源:腳本之家

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

私有倉庫最常用的就是Registry、Harbor兩種,那接下來詳細介紹如何搭建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宿主機開啟路由功能-->
[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
 <!--運行registry容器,運行registry服務(wù)存儲自己的鏡像-->
 <!--"--restart=always"參數(shù)是指此容器跟隨docker服務(wù)啟動而啟動-->
[root@centos01 ~]# docker ps  <!--查看docker運行的容器-->
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  
    <!--修改鏡像標簽-->
[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添加一個身份驗證,只有通過了身份驗證才可以上傳或者下載私有倉庫中的鏡像。

三、配置registry加載身份驗證

[root@centos01 ~]# yum -y install httpd-tools  <!--安裝加密工具httpd-tools-->
[root@centos01 ~]# mkdir /opt/registry-auth <!--創(chuàng)建存放驗證密鑰目錄-->
[root@centos01 ~]# htpasswd -Bbn bob pwd@123 > /opt/registry-auth/htpasswd
 <!--配置registry身份驗證數(shù)據(jù)庫-->
<!--"-Bbn”參數(shù)解釋:B強制密碼加密;b在命令中輸入密碼,不提示輸入密碼;n不更新密鑰文件-->
<!--刪除此服務(wù)器上的所有容器,接下來重新生成一個需要身份驗證的私有倉庫容器-->
[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 
 <!--重新運行一個支持身份驗證的registry私有鏡像倉庫容器-->
[root@centos01 ~]# docker tag tomcat:latest 192.168.100.10:5000/image/tomcat:1.0 
    <!--鏡像修改標簽-->
[root@centos01 ~]# docker push 192.168.100.10:5000/image/tomcat:1.0 
<!--測試不通過身份驗證是否可以往私有倉庫上傳鏡像-->
no basic auth credentials
<!--提示沒有身份驗證,上傳不了-->
[root@centos01 ~]# docker login 192.168.100.10:5000 
    <!--登錄私有鏡像倉庫,通過身份驗證即可上傳-->
Username: bob   <!--輸入bob-->
Password:    <!--輸入密碼-->
……………… <!--此處省略部分內(nèi)容-->
Login Succeeded     <!--已通過身份驗證,此時可以上傳鏡像到私有倉庫-->
[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客戶端不通過身份驗證直接下載私有倉庫中的鏡像直接被拒絕-->
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 
    <!--登錄私有倉庫,通過身份驗證-->
Username: bob  <!--輸入bob-->
Password:     <!--輸入密碼-->
Login Succeeded   <!--通過身份驗證-->
[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部署的實現(xiàn)的文章就介紹到這了,更多相關(guān)Docker私有倉庫Registry內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

美國服務(wù)器租用

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部