简介
Docker离不开可靠的镜像管理,官方默认的DockHub,虽然Docker官方也提供了公共的镜像仓库Registry,但是功能略显简单。
Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。
系统环境(harbor需要docker-compose)
#docker version
docker version 19.03.1
#docker-compose version
docker-compose version 1.18.0
#harbor版本:
v1.9.4
下载安装包
官方安装文档地址:
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
harbor安装分为离线和在线安装,本次使用的是离线安装
安装包下载地址:
https://github.com/goharbor/harbor/releases
wget https://github.com/goharbor/harbor/releases/download/v1.9.4/harbor-offline-installer-v1.9.4.tgz
tar zxvf harbor-offline-installer-v1.9.4.tgz
cd harbor/
修改配置文件harbor.yml
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 172.16.10.54
# http related config
http:
port: 18180
harbor_admin_password: Harbor12345
# Harbor DB configuration
database:
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
max_open_conns: 1000
data_volume: /root/work/harbor/data
clair:
updaters_interval: 12
trivy:
ignore_unfixed: false
skip_update: false
jobservice:
max_job_workers: 10
notification:
webhook_job_max_retry: 10
chart:
absolute_url: disabled
log:
level: info
local:
rotate_count: 50
rotate_size: 200M
location: /root/work/harbor/logs
_version: 2.0.0
proxy:
http_proxy:
https_proxy:
no_proxy:
components:
- core
- jobservice
- clair
- trivy
执行安装
./install.sh --with-clair #加--with-clair可以检查镜像的安全漏洞
升级docker-compose
curl -L https://github.com/docker/compose/releases/download/1.27.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
安装完后执行docker-compose ps查看启动的容器:
docker-compose ps
Harbor启动停止方法
docker-compose stop
docker-compose start
docker-compose restart
启动Harbor
用户名密码为harbor.yml中配置的,默认为admin/Harbor12345
我们新建一个仓库elvis_image测试用
配置docker信任仓库
因为docker默认使用https连接镜像仓库,而此处harbor配置使用的是http,所以需要配置docker节点文件信任此仓库(所有需要使用仓库的主机都需要操作一步这个)
vim /etc/docker/daemon.json
######
{
"insecure-registries": ["172.16.10.54:18180"]
}
第一次push之前需要使用docker login 登陆验证下(所有需要使用仓库的主机都需要操作一步这个):
docker login 172.16.10.54:18180
######
Username: admin
Password:
Login Succeeded
相关用户名密码等会存储在/root/.docker/config.json文件里
如果有上述错误,可以进行以下处理
sudo apt-get remove golang-docker-credential-helpers
测试推送镜像到harbor
docker images
docker image tag minio/minio:latest 172.16.10.54:18180/elvis_image/minio:latest
docker push 172.16.10.54:18180/elvis_image/minio:latest
测试拉取harbor镜像
#先删除之前镜像
docker rmi 172.16.10.54:18180/elvis_image/minio
#拉去镜像
docker pull 172.16.10.54:18180/elvis_image/minio