使用harbor配置docker registry
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用harbor配置docker registry相关的知识,希望对你有一定的参考价值。
前面连说了几篇与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共有六个容器组成:
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]163.com email_password = xxxxx email_from = admin <[email protected]163.com> 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访问界面如下:
以上是关于使用harbor配置docker registry的主要内容,如果未能解决你的问题,请参考以下文章