官方的离线安装包是 AMD64 版本的,不支持 M 系芯片的 Mac,会出现如下报错,所以要找社区编译的 ARM 版本。
shell
Prepare base dir is set to /Users/iven/Downloads/harbor
WARNING: The requested image's platform (linux/amd 64) does not match the detected host platform (linux/arm 64/v 8) and no specific platform was requested
所需环境
- Docker Desktop
- Docker-compose
下载安装包
shell
wget https://github.com/wise2c-devops/build-harbor-aarch64/releases/download/v2.10.2/harbor-offline-installer-aarch64-v2.10.2.tgz
更改配置文件
shell
# 解压
tar xvf harbor-offline-installer-aarch64-v2.10.2.tgz
# 进入harbor目录
cd harbor
# 重命名yml配置文件
mv harbor.yml.tmpl harbor.yml
# 修改配置文件
vim harbor.yml



在 Docker Desktop 中输入快捷键 cmd .
进入偏好设置:
安装
shell
./install.sh
最终会启动 10 个容器
启动和停止
shell
# 在harbor目录下操作
# 停止(加上-v参数会连带删除数据卷)
docker-compose stop
# 删除容器(加上-v参数会连带删除数据卷)
docker-compose down -v
# 后台启动
docker-compose up -d
# 重新构建并启动
docker-compose up --build -d
访问
浏览器进入: http://<设置的hostname>:80

修改 Docker 配置
Linux 虚拟机中可以这么配置:
shell
# 由于docker默认不允许使用非https方式推送镜像,所以在需要pull镜像的服务器配置访问地址
vim /etc/docker/daemon.json
#添加如下内容(客户端访问的网址):
"registry-mirrors":[
"https://njrds9qc.mirror.aliyuncs.com"
],
"insecure-registries" :[
"192.168.31.48:80"
]
# 重启docker
systemctl restart docker
# 重启harbor容器,要在harbor目录下操作
docker-compose stop
docker-compose up -d
Mac 上直接在 Docker Desktop 配置:
推送镜像(以官方 nginx 镜像为例)
- 准备工作:登陆 harbor,打标签
shell
# docker登陆harbor
docker login 192.168.31.48:80 -u admin
# 给nginx镜像打一个标签
# 格式: docker tag 镜像名:版本 your-ip:端口/项目名称/新的镜像名:版本
docker tag nginx:latest 192.168.31.48:80/library/nginx:latest
结果如下:
shell
➜ harbor docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.31.48:80/library/nginx latest 47ef8710c9f5 3 weeks ago 198MB
nginx latest 47ef8710c9f5 3 weeks ago 198MB
- 开始推送
shell
➜ harbor docker push 192.168.31.48:80/library/nginx:latest
The push refers to repository [192.168.31.48:80/library/nginx]
be61b0da9648: Pushed
58d58d2ade95: Pushed
beb3bb225b88: Pushed
bdc4a6d15284: Pushed
4b950e3c58cf: Pushed
e0ed4995377a: Pushed
f0f023a63482: Pushed
latest: digest: sha256:148cb3109165d936620429e68a78b0880009148826cc0900c5de1d04f5694061 size: 1778
