1. 程式人生 > 實用技巧 >docker私有倉庫harbor的安裝及使用

docker私有倉庫harbor的安裝及使用

harbor官方文件
環境說明

主機IP
docker 192.168.20.135

安裝harbor

1.安裝docker-compose

[root@docker ~]# yum -y install docker-compose

2.將壓縮包解壓

[root@docker ~]# cd /usr/src/
[root@docker ~]# wget https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz

[root@docker ~]# tar
xf harbor-offline-installer-v2.0.2.tgz -C /usr/local/ [root@docker ~]# cd /usr/local/harbor [root@docker harbor]# ls common.sh harbor.yml.tmpl LICENSE harbor.v2.0.2.tar.gz install.sh prepare

3.複製harbor.yml.tmpl檔案為harbor.yml

[root@docker harbor]# cp harbor.yml.tmpl harbor.yml

4.修改配置檔案

詳細配置資訊

//改為本機IP
hostname: 192.168.20.135

//沒有配置ssl證書就註釋掉
# https related config
#https:
  # https port for harbor, default is 443
#  port: 443
  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path


//使用者名稱admin,密碼Harbor12345
# The initial password of Harbor admin
# It only works 
in first time to install harbor # Remember Change the admin password from UI after launching Harbor. harbor_admin_password: Harbor12345

啟動

[root@docker harbor]# systemctl start docker
[root@docker harbor]# ./install.sh----Harbor has been installed and started successfully.----
[root@docker harbor]# 
[root@docker harbor]# 
[root@docker harbor]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    127.0.0.1:1514                *:*                  
LISTEN      0      128    :::80                 :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  

使用Harbor

登入



我們可以看到系統各個模組如下:

專案:新增/刪除專案,檢視映象倉庫,給專案新增成員、檢視操作日誌、複製專案等
日誌:倉庫各個映象create、push、pull等操作日誌

系統管理

  • 使用者管理:新增/刪除使用者、設定管理員等
  • 倉庫管理:新增/刪除從庫目標、新建/刪除/啟停複製規則等
  • 複製管理:認證模式、複製、郵箱設定、系統設定等
  1. 標籤新增到本專案的映象中。
    • 全域性級別標籤:由系統管理員管理,用於管理整個系統的映象。它 們可以新增到任何專案下的映象中。
    • 專案級別標籤:由專案管理員或者系統管理員在專案下管理,只能
  2. 專案定額:分配每個專案多少儲存空間
  3. 審查服務:掃描漏銅
  4. 垃圾清理:清理不需要的映象
  5. 配置管理:認證設定、郵箱設定、系統設定

注意:非系統管理員使用者登入,只能看到有許可權的專案和日誌,其他模組不可見。

登入傳映象了

我們需要在/etc/docker/daemon.json加上 “insecure-registries”:[“harborIP”]

[root@docker ~]# vim /etc/docker/daemon.json
[root@docker ~]# cat /etc/docker/daemon.json
{
    "registry-mirrors": ["https://0v0l236l.mirror.aliyuncs.com"],
    "insecure-registries":["192.168.20.135"]
}



//重啟服務
[root@docker harbor]# systemctl restart docker


//登入
[root@docker harbor]# docker login 192.168.20.135
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

//改標籤
[root@docker ~]# docker tag nginx:latest 192.168.20.135/nginx/nginx:v0.1


[root@docker ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
192.168.20.135/nginx/nginx      v0.1                4bb46517cac3        2 weeks ago         133MB
nginx                           latest              4bb46517cac3        2 weeks ago         133MB

//上傳映象到harbor倉庫

[root@docker ~]# docker push 192.168.20.135/nginx/nginx:v0.1
The push refers to repository [192.168.20.135/nginx/nginx]
550333325e31: Pushed 
22ea89b1a816: Pushed 
a4d893caa5c9: Pushed 
0338db614b95: Pushed 
d0f104dc0a1f: Pushed 
v0.1: digest: sha256:179412c42fe3336e7cdc253ad4a2e03d32f50e3037a860cf5edbeb1aaddb915c size: 1362

建立使用者,分配許可權


新增到nginx專案中,並設定許可權

[root@localhost ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://0v0l236l.mirror.aliyuncs.com"],
    "insecure-registries":["192.168.20.135"]
}

[root@localhost ~]# systemctl restart docker

登入

[root@localhost ~]# docker login 192.168.20.135
Username: zzl
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

上傳映象

[root@localhost ~]# docker tag nginx:latest 192.168.20.135/nginx/nginx:v0.2
[root@localhost ~]# docker push 192.168.20.135/nginx/nginx:v0.2
The push refers to repository [192.168.20.135/nginx/nginx]
550333325e31: Layer already exists 
22ea89b1a816: Layer already exists 
a4d893caa5c9: Layer already exists 
0338db614b95: Layer already exists 
d0f104dc0a1f: Layer already exists 
v0.2: digest: sha256:179412c42fe3336e7cdc253ad4a2e03d32f50e3037a860cf5edbeb1aaddb915c size: 1362

Docker 映象複製

harborIP
docker 192.168.20.135/24
harbor002 192.168.20.99/24

在倉庫管理,新建一個目標


同步

在192.168.20.99上檢視,同步完成