手把手教你搭建Docker私有倉庫


章節一:centos7 docker安裝和使用_入門教程

章節二:使用docker部署Asp.net core web應用程序

有了前面的基礎,接下來的操作就比較簡單了。先准備兩台虛擬機,兩台機器上都配好yum源,安裝好docker,設置好docker加速器。

Docker客戶端:192.168.1.160;Docker私有倉庫服務器:192.168.1.161

1.在服務端192.168.1.161上拉取倉庫鏡像:registry

[root@localhost ~]# docker pull registry 

2.在服務端192.168.1.161運行docker私有倉庫

[root@localhost ~]# docker run -d -v /registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest

如果成功執行,則表示我們的docker私有倉庫搭建成功。

下面對這條命令的部分內容做下說明。

/registry表示宿主機目錄,該目錄如果不存在會自動創建。

docker -v 宿主機目錄:容器目錄

在網上看到的解釋:

把宿主機的目錄掛載到容器中

或者

把docker 容器中某目錄的數據 加載到 宿主機的某個目錄

這樣做的目的是為了防止docker私有倉庫這個容器被刪除時,倉庫里的鏡像也會被刪除。

3.在客戶端制作鏡像

以hello-world為例,先把它拉取下來

[root@localhost ~]# docker pull hello-world

給hello-world鏡像打個tag,表示新的版本

[root@localhost ~]# docker tag hello-world 192.168.1.161:5000/hello-world:latest 

4.將新的hello-world鏡像上傳到私有倉庫

[root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

發現會報以下錯誤:

The push refers to a repository [192.168.1.161:5000/hello-world]
Get https://192.168.1.161:5000/v1/_ping: http: server gave HTTP response to HTTPS client

原因是docker私有倉庫服務器,默認是基於https傳輸的,所以我們需要在客戶端192.168.1.160做相關設置,不使用https傳輸

[root@localhost ~]# vi /etc/docker/daemon.json

將下面的代碼放進去保存並退出。

"insecure-registries":["192.168.1.161:5000"]

最終如下所示:

{
        "registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],
        "insecure-registries":["192.168.1.161:5000"]
}

依次執行下面兩條命令,重新啟動docker:

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

再次執行推送命令:

[root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

5.在私有倉庫192.168.1.161查看上傳的鏡像

[root@localhost repositories]# ls /registry/docker/registry/v2/repositories

或者在客戶端執行以下命令查看:

[root@localhost ~]# curl http://192.168.1.161:5000/v2/_catalog

會輸出:

{"repositories":["hello-world"]}

好,大功告成。

 

參考地址:

https://blog.csdn.net/mmd0308/article/details/77162004

https://www.cnblogs.com/Javame/p/7389093.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM