1. 程式人生 > >使用harbor配置docker registry

使用harbor配置docker registry

kuberntes

前面連說了幾篇與kubernetes相關的內容,這篇我們來說說docker registry。docker的registry與kubernetes本身並沒有太直接的關系。但是任何使用到docker的地方,總少不了這玩藝兒。所以這篇博文我們專門來說一說如何使用開源的harbor來配置管理我們的私有registry。

  harbor官方是這麽描述harbor的:Harbor是可靠的企業級Registry服務器。企業用戶可使用Harbor搭建私有容器Registry服務,提高生產效率和安全度,既可應用於生產環境,也可以在開發環境中使用。github地址:https://github.com/vmware/harbor


  需要說明的是,由於harbor只支持registry v2的api,所以對docker的版本也是有要求的,至少得>=1.6.0。同時harbor的安裝還依賴於docker-compose,當然官方也提供直接使用kubernetes部署的yml文件。所以其實我們可以想見,harbor的部署一定是以容器的形式來完成的

harbor共有六個容器組成:
harbor_ui:harbor的核心服務。
harbor_log:運行著rsyslog的容器,進行日誌收集。
harbor_mysql:由官方mysql鏡像構成的數據庫容器
nginx:使用Nginx做反向代理
registry:官方的Docker registry
harbor_jobservice:Harbor的任務管理服務。

我這裏的安裝環境依然是基於centos 7.2。
首先安裝docker-compose:

pip install docker-compose

下載docker的安裝包:

git clone https://github.com/vmware/harbor

cd harbor/make/

修改配置文件harbor.cfg如下:
復制代碼

hostname = myhub.xxx.com
ui_url_protocol = https

email_server = smtp.163.com
email_server_port = 25
email_username = [email protected]
/* */
email_password = xxxxx
email_from = admin <[email protected]>
email_ssl = false
harbor_admin_password = xxx
ssl_cert = /data/server/harbor/make/cert/xxx.com.crt
ssl_cert_key = /data/server/harbor/make/cert/xxx.com.key

復制代碼

其中兩個ssl證書文件需要自行申請或者直接使用自簽名證書。生成自簽名證書的方法,在這裏不做相關說明。

修改docker-compose.yml文件
復制代碼

cp docker-compose.tpl docker-compose.yml

vim docker-compose.yml

version: ‘2‘
services:
log:
image: myhub.fdccloud.com/library/harbor-log
container_name: harbor-log
restart: always
volumes:
- /data/harbor/log/:/var/log/docker/
ports:
- 1514:514
registry:
image: myhub.fdccloud.com/library/registry:2.5.0
container_name: registry
restart: always
volumes:
- /data/registry:/storage
- ./common/config/registry/:/etc/registry/
environment:
- GODEBUG=netdns=cgo
command:
["serve", "/etc/registry/config.yml"]
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
mysql:
image: myhub.fdccloud.com/library/harbor-db
container_name: harbor-db
restart: always
volumes:
- /data/harbor/harbordb:/var/lib/mysql
env_file:
- ./common/config/db/env
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "mysql"
ui:
image: myhub.fdccloud.com/library/harbor-ui
container_name: harbor-ui
env_file:
- ./common/config/ui/env
restart: always
volumes:
- ./common/config/ui/app.conf:/etc/ui/app.conf
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem
- /data/harbor/harbor_storage:/harbor_storage
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "ui"
jobservice:
image: myhub.fdccloud.com/library/harbor-jobservice
container_name: harbor-jobservice
env_file:
- ./common/config/jobservice/env
restart: always
volumes:
- /data/harbor/job_logs:/var/log/jobs
- ./common/config/jobservice/app.conf:/etc/jobservice/app.conf
depends_on:
- ui
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
proxy:
image: myhub.fdccloud.com/library/nginx:1.11.5
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx
ports:
#- 80:80
- 443:443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"

復制代碼

創建映射的相關目錄:

mkdir -p /data/harbor/{harbordb,harbor_storage,job_logs,log}
mkdir /data/registry

執行harbor安裝並啟動:

./install.sh

也可以通過如下方式啟動:

./prepare
docker-compose -f docker-compose.yml up -d

harbor訪問界面如下:

技術分享


本文出自 “我的天空” 博客,請務必保留此出處http://sky66.blog.51cto.com/2439074/1934001

使用harbor配置docker registry