簡介
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