harbor 搭建及使用

BUG弄潮儿發表於2024-10-19

docker-compose

下載

curl -L https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64 > /usr/local/bin/docker-compose

增加許可權

sudo chmod +x /usr/local/bin/docker-compose

查詢docker-compose版本

docker-compose -v

Harbor

下載

wget https://kkgithub.com/goharbor/harbor/releases/download/v2.11.1/harbor-offline-installer-v2.11.1.tgz

解壓

tar -zxvf harbor-offline-installer-v2.11.1.tgz

建立Harbor持久化檔案目錄

用於存放harbor的持久化資料

mkdir -p /opt/harbor

配置

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

cp harbor.yml.tmpl  harbor.yml

harbor.yml配置檔案主要修改引數如下


hostname: 10.0.2.11:9999          #設定訪問地址,可以使用ip、域名,不可以設定為127.0.0.1或localhost。預設情況下,harbor使用的埠是80,若使用自定義的埠,除了要改docker-compose.yml檔案中的配置外,這裡的hostname也要加上自定義的埠,否則在docker login、push時會報錯

#http配置
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 9999                      

#https配置(如不需要可不配置,註釋掉)
# 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

#external_url: https://reg.mydomain.com:8433      #如果要啟用外部代理,比如外層的NGINX、LB等,請取消註釋external_url,當它啟用時,hostname將不再使用。

harbor_admin_password: Harbor12345         #admin密碼

 

#資料庫配置
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 100 for postgres.
max_open_conns: 100


#持久化資料目錄
data_volume: /opt/harbor

安裝並啟動Harbor

./install.sh

後續如果關閉或者重啟Harbor可以直接使用如下命令;先切換到Harbor安裝的跟目錄

docker-compose start
docker-compose stop

訪問Harbor

http://10.0.2.11:9999
admin / Harbor12345

在Harbor中新建專案

Harbor的使用

修改Docker的配置檔案/etc/docker/daemon.json

{
 "exec-opts": ["native.cgroupdriver=systemd"],
 "registry-mirrors": [
	  "https://rg6pgcdd.mirror.aliyuncs.com",
      "https://docker.m.daocloud.io", 
      "https://noohub.ru", 
      "https://huecker.io",
      "https://dockerhub.timeweb.cloud"
  ],
  "insecure-registries": ["10.0.2.11"]    
}

重新啟動docker

systemctl daemon-reload
systemctl restart docker

登入Harbor

docker login 10.0.2.11:9999

輸入Harbor的使用者和密碼

給構建好的映象打標籤

docker tag nginx:v1.0 10.0.2.11/m-k8s/nginx:v1.0

10.0.2.11/m-k8s/nginx:v1.0需要跟在Harbor建立的專案路徑進行對應

上傳映象

docker push nginx:v1.0 10.0.2.11/m-k8s/nginx:v1.0

驗證拉取映象

先刪除本地打tag的映象

docker rmi 10.0.2.11/m-k8s/nginx:v1.0

拉取Harbor的映象

docker pull 10.0.2.11/m-k8s/nginx:v1.0
docker images
參考:www.cnblogs.com/wxwgk/p/13287336.html

相關文章