环境准备
ubuntu
root@xxx:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04 LTS Release: 22.04 Codename: jammy
docker
和docker-compose
root@xxx:~# docker version Client: Docker Engine - Community Version: 20.10.18 API version: 1.41 Go version: go1.18.6
root@xxx:~# docker-compose -version docker-compose version 1.29.2, build unknown
注意:Harbor的所有服务组件都是docker
中部署的,官方建议使用docker-compose
,所有需要安装docker
和docker-compose
,由于harbor
是基于docker registry v2
版本,所有要求docker
版本不小于1.10.0
,docker-compose
版本不小于1.6
安装harbor
harbor支持在线和离线安装方式,建议使用离线安装方式,先下载harbor的安装地址
https://github.com/goharbor/harbor/releases
,选择离线安装包
1、 下载离线安装包之后,解压
cd /data/harbor
cp harbor.yml.tmpl harbor.yml
vim harbor.yml #编辑
2、 修改harbor.yml
内容
hostname = 192.168.1.100 # 修改harbor的启动ip,为当前ip
port:86 # 修改监听端口为 86,默认为80
harbor_admin_password = harbor123456
data_volume: /harbor/data # 修改harbor的存储位置
3、执行 ./prepare
配置harbor
root@xxx:/data/harbor# ./prepare
prepare base dir is set to /data/harbor
/usr/src/app/utils/configs.py:100: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
configs = yaml.load(f)
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
/usr/src/app/utils/configs.py:90: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
versions = yaml.load(f)
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /secret/keys/secretkey
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secret/registry/root.crt
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
4、执行安装./install.sh
安装harbor,看到下图执行安装成功
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating registry ... done
Creating redis ... done
Creating harbor-db ... done
Creating registryctl ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
5、访问配置的ip:port
,默认的用户名admin
,密码为上述harbor.yml
配置的密码:Harbor12345
使用harbor
win10
下的docker-desktop
在配置Docker Engine中新增
"insecure-registries": [
"192.168.2.84:86" // 对应的harbor主机和端口
]
重启docker之后,
PS C:\Users\Administrator> docker login 192.168.2.84:86
Username: admin
Password:
Login Succeeded
提示登录成功
推送本地镜像
package main
import "fmt"
func main(){
fmt.Println("hello harbor")
}
FROM golang:1.18 as builder
WORKDIR /app
COPY ../ /app
RUN cd /app && go build -o hello
FROM alpine:3.10
WORKDIR /app
COPY --from=builder /app/ /app/
ENTRYPOINT ./hello
本地打包命令
docker build -t 192.168.2.84:86/default/hello:v1 .
打包完成之后,直接执行docker push 192.168.2.84:86/default/hello:v1