這篇文章將為大家詳細講解有關docker私有倉庫如何搭建,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設計、網(wǎng)站制作與策劃設計,離石網(wǎng)站建設哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設10年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:離石等地區(qū)。離石做網(wǎng)站價格咨詢:13518219792查看docker-registry版本信息:
[root@docker-registry ~]# yum info docker-registry Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn Available Packages Name : docker-registry Arch : x86_64 Version : 0.9.1 Release : 7.el7 Size : 123 k Repo : extras/7/x86_64 Summary : Registry server for Docker URL : https://github.com/docker/docker-registry License : ASL 2.0 Description : Registry server for Docker (hosting/delivering of repositories and images).
安裝docker-registry:
[root@docker-registry ~]# yum -y install docker-registry
查看安裝后docker-distribution的的配置文件位置
[root@docker-registry ~]# rpm -ql docker-distribution /etc/docker-distribution/registry/config.yml /usr/bin/registry /usr/lib/systemd/system/docker-distribution.service /usr/share/doc/docker-distribution-2.6.2 /usr/share/doc/docker-distribution-2.6.2/AUTHORS /usr/share/doc/docker-distribution-2.6.2/CONTRIBUTING.md /usr/share/doc/docker-distribution-2.6.2/LICENSE /usr/share/doc/docker-distribution-2.6.2/MAINTAINERS /usr/share/doc/docker-distribution-2.6.2/README.md /var/lib/registry #數(shù)據(jù)放在這個目錄下,可以修改/etc/docker-distribution/registry/config.yml改這個路徑
查看配置文件:
[root@docker-registry ~]# cat /etc/docker-distribution/registry/config.yml version: 0.1 log: fields: service: registry storage: cache: layerinfo: inmemory filesystem: rootdirectory: /var/lib/registry #鏡像存儲位置,可以修改成自己的 http: addr: :5000 #監(jiān)聽端口為5000
啟動服務:
[root@docker-registry ~]# systemctl start docker-distribution [root@docker-registry ~]# systemctl enable docker-distribution Created symlink from /etc/systemd/system/multi-user.target.wants/docker-distribution.service to /usr/lib/systemd/system/docker-distribution.service.
這樣我們就裝好了docker-registry。
下面我們測試,把node3機器上的鏡像推到docker-registry機器上。
[root@k8s-node3 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7.22 6bb891430fb6 3 months ago 372 MB
我們準備把node3上的mysql:5.7.22鏡像推到docker-registry機器上,需要先給node3機器上的鏡像mysql打標簽:
[root@k8s-node3 ~]# docker tag mysql:5.7.22 docker-registry:5000/mysql:5.7.22
[root@k8s-node3 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker-registry.com:5000/mysql 5.7.22 6bb891430fb6 3 months ago 372 MB
注意,docker-registry是主機名,要用hosts文件解析到對應的registryip地址上。
[root@k8s-node3 ~]# docker push docker-registry:5000/mysql:5.7.22 The push refers to a repository [docker-registry:5000/mysql] Get https://docker-registry:5000/v1/_ping: http: server gave HTTP response to HTTPS client
注意:如果上面寫作docker-registry:5000/mysql,說明推送的是mysql頂級倉庫下所有的鏡像版本。
上面看到,我們docker push 時報錯了,這是因為docker 客戶端默認使用的https形式的,但是dockr registry server端是http形式的。
如果我們實在就用http的,那就需要對docker 客戶端做如下修改:
[root@k8s-node3 ~]# vim /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["docker-registry:5000"] }
注意,上面的dokcer-registry是主機名。
[root@k8s-node3 ~]# systemctl restart docker
然后再推就能推上去了。
[root@k8s-node3 ~]# docker push docker-registry:5000/mysql:5.7.22 The push refers to a repository [docker-registry:5000/mysql] a968f24d4187: Pushed f8cb294d5d80: Pushed 489bddb9c55e: Pushed 22b402e93939: Pushed 8aeebb3964c1: Pushed 94f8d8f5acbf: Pushed c0c26734fb83: Pushed 4801a487d51a: Pushed aae63f31dee9: Pushed 6f8d38b0e2b6: Pushed cdb3f9544e4c: Pushed 5.7.22: digest: sha256:1d3119703eb04855c971a9ec24646184444fa1bd889b201de3ce8904c35eb627 size: 2621
然后,我們登錄到docker registry服務器,就能看到推送過來的鏡像了:
[root@docker-registry ~]# ll /var/lib/registry/docker/registry/v2/repositories/mysql/ total 0 drwxr-xr-x. 3 root root 20 Oct 25 05:13 _layers drwxr-xr-x. 4 root root 35 Oct 25 05:14 _manifests drwxr-xr-x. 2 root root 6 Oct 25 05:14 _uploads
下面我們就讓其他服務器從docker-registry服務器上下載鏡像。
首先也需要在其他服務器上更改docker配置,加個"insecure-registries"參數(shù),如下:
[root@k8s-node1 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["docker-registry:5000"] }
[root@k8s-node1 ~]# systemctl restart docker
然后在這個機器上下載docker-registry機器上的鏡像:
[root@k8s-node1 ~]# docker pull docker-registry:5000/mysql:5.7.22 5.7.22: Pulling from mysql 2da35ff30a7d: Pull complete 46459f75a599: Pull complete fe071c86fe94: Pull complete 75457c650197: Pull complete 6506db22c932: Pull complete a6e0a2acd728: Pull complete 3182738b1913: Pull complete ea75bfdf07be: Pull complete 6b85e8810885: Pull complete 5dca51ac89bd: Pull complete b3400d337f49: Pull complete Digest: sha256:1d3119703eb04855c971a9ec24646184444fa1bd889b201de3ce8904c35eb627 Status: Downloaded newer image for docker-registry:5000/mysql:5.7.22
[root@k8s-node1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 05af71dd9251 8 days ago 463 MB docker-registry:5000/mysql 5.7.22 6bb891430fb6 3 months ago 372 MB
看到下載的鏡像就是我們私有倉庫里面的。
我們看到上面搭建的docker私有倉庫是命令行界面的,很丑陋。不過,好消息是,目前有個開源項目叫harbor,是在docker registry基礎上做的,并帶了個漂亮的web界面,還支持冗余等。是個非常不錯的項目。另外,CNCF組織也非常青睞harbor,可見harbor的前景非常不錯。
可是,harbor的部署是非常麻煩的。還好,現(xiàn)在可以用docker compose(單機編排工具)來做harbor的安裝。
下面我們準備安裝harbor試一下。
官方項目地址是: https://github.com/goharbor/harbor
官方安裝文檔:https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
harbor官方要求配置為:
Software | Version | Description |
---|---|---|
Python | version 2.7 or higher | Note that you may have to install Python on Linux distributions (Gentoo, Arch) that do not come with a Python interpreter installed by default |
Docker engine | version 1.10 or higher | For installation instructions, please refer to: https://docs.docker.com/engine/installation/ |
Docker Compose | version 1.6.0 or higher | For installation instructions, please refer to: https://docs.docker.com/compose/install/ |
Openssl | latest is preferred | Generate certificate and keys for Harbor |
先安裝epel源。
[root@harbor yum.repos.d]# cd /etc/yum.repos.d/ [root@harbor yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
看epel里面的docker-compose版本情況:
[root@docker-registry yum.repos.d]# yum info docker-compose epel 12742/12742 Available Packages Name : docker-compose Arch : noarch Version : 1.18.0 Release : 1.el7 Size : 226 k Repo : epel/x86_64 Summary : Multi-container orchestration for Docker URL : https://github.com/docker/compose License : ASL 2.0
登錄 https://github.com/goharbor/harbor/releases下載harbor。
我們下載二進制的安裝包:
[root@harbor ~]# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz
[root@harbor ~]# tar -xvf harbor-offline-installer-v1.6.1.tgz -C /usr/local/
編輯配置文件:
[root@harbor ~]# cd /usr/local/harbor/
[root@docker-registry harbor]# vim harbor.cfg hostname = 172.16.22.196 #harbor服務器的名稱,可以是IP地址(本機ip),或者是完整的域名,不要使用localhost或者127.0.0.1,因為服務需要被其他的機器訪問 ui_url_protocol = http max_job_workers = 10 #小于操作系統(tǒng)的cpu個數(shù) harbor_admin_password = Harbor12345 #admin的密碼
停止我們前面安裝的docker-distribution
[root@harbor harbor]# systemctl stop docker-distribution
安裝docker-compose
[root@docker-registry harbor]# yum install docker-compose
安裝docker:
[root@harbor harbor]#yum intall docker-ce [root@harbor harbor]# systemctl start docker
安裝harbor:
[root@harbor harbor]# ./prepare [root@harbor harbor]# ./install.sh [Step 0]: checking installation environment ... Note: docker version: 18.06.1 Note: docker-compose version: 1.18.0
安裝過程時間比較長,原因是它需要展開harbor.v1.6.1.tar.gz鏡像,并安裝這些鏡像。
安裝完后,訪問 http://172.16.22.196,默認用戶名admin,密碼Harbor12345
登錄后,我們建立一個普通用戶:
創(chuàng)建一個項目:
備注:上面的復制管理就是用來給harbor做主從復制的。
然后以普通用戶登錄,并創(chuàng)建一個項目:
我們登錄另外一個機器node03當做客戶端,然后在這個機器上修改客戶端以http方式訪問harbor server(我這里ip是172.16.22.196):
[root@k8s-node3 ~]# vim /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["172.16.22.196"] }
[root@k8s-node3 ~]# systemctl daemon-reload [root@k8s-node3 ~]# systemctl restart docker
然后給node3的鏡像打標簽,打成harbor主機名形式:
[root@k8s-node3 ~]# docker tag mysql:5.7.22 172.16.22.196/dev/mysql:5.7.22
在node3機器上,登錄docker-registry(172.16.22.196)
[root@k8s-node3 ~]# docker login 172.16.22.196 Username: chenzhixin Password: Login Succeeded
把node3上的鏡像推送到harbor server172.16.22.196上:
[root@k8s-node3 ~]# docker push 172.16.22.196/dev/mysql #不加標簽標示把mysql下所有標簽的鏡像都推送到harbor上 The push refers to a repository [172.16.22.196/dev/mysql] a968f24d4187: Pushed f8cb294d5d80: Pushed 489bddb9c55e: Pushed 22b402e93939: Pushed 8aeebb3964c1: Pushed 94f8d8f5acbf: Pushed c0c26734fb83: Pushed 4801a487d51a: Pushed aae63f31dee9: Pushed 6f8d38b0e2b6: Pushed cdb3f9544e4c: Pushed 5.7.22: digest: sha256:1d3119703eb04855c971a9ec24646184444fa1bd889b201de3ce8904c35eb627 size: 2621
然后我們就能在harbor server上看到我們推送的鏡像了:
Harbor容器的stop與start:
進入Harbor目錄執(zhí)行如下命令即可: cd /usr/local/harbor docker-compose stop/start
其他補充知識:
/usr/local/harbor/docker-compose.yml :這個文件里面定義了數(shù)據(jù)存放的目錄是:/data
[root@harbor harbor]# ls /data/ ca_download config database job_logs psc redis registry secretkey
關于“docker私有倉庫如何搭建”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。