Harbor介绍
Harbor 是一个企业级的云原生容器镜像仓库,由 VMware 主导开发并贡献给 Cloud Native Computing Foundation (CNCF)。它通过为 Docker 镜像提供安全、高效的管理能力,帮助企业简化容器应用程序的交付流程。
相比于传统的 Docker Registry,Harbor 提供了更多的企业级特性,如容器镜像仓库之间的镜像复制、用户管理、访问控制、漏洞扫描和镜像签名等功能。
harbor 部署
前提条件
- 部署docker环境
- 下载docker-compose
curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o docker-compose
第1步:下载harbor源码
可以在harbor官网下载harbor源码。
1.使用curl 命令下载
[root@docker harbor]# curl -SL https://github.com/goharbor/harbor/releases/download/v2.7.1/harbor-offline-installer-v2.7.1.tgz
[root@docker harbor]# ls
harbor-offline-installer-v2.7.1.tgz
2.解压
[root@docker harbor]# tar xf harbor-offline-installer-v2.7.1.tgz
[root@docker harbor]# ls
harbor harbor-offline-installer-v2.7.1.tgz
第2步:备份 harbor.yml,修改 harbor.yml配置。
1.备份 harbor.yml
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
2.修改harbor.yaml
[root@harbor harbor]# vim harbor.yml
hostname: 192.168.102.136 #修改为主机ip
port: 8089 #端口号也可以不修改;建议修改,以防端口号被占用
# 注释掉https的配置 #没有用到,建议注释。
第3步:授予docker-compose 可执行权限
1.复制docker-compose到/usr/bin,可以在环境变量中找到。
[root@docker harbor]# cp docker-compose /usr/bin/
2. 授予可执行权限
[root@docker harbor]# chmod +x docker-compose
第4步:执行脚本install.sh
[root@docker harbor]# ls
common docker-compose.yml harbor.yml.tmpl LICENSE
common.sh harbor.v2.7.1.tar.gz install.sh prepare
docker-compose harbor.yml
[root@docker harbor]# ./install.sh
#查看容器是否启动
[root@docker harbor]# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
harbor-core goharbor/harbor-core:v2.7.1 "/harbor/entrypoint.…" core 22 minutes ago Up 22 minutes (healthy)
harbor-db goharbor/harbor-db:v2.7.1 "/docker-entrypoint.…" postgresql 22 minutes ago Up 22 minutes (healthy)
harbor-jobservice goharbor/harbor-jobservice:v2.7.1 "/harbor/entrypoint.…" jobservice 22 minutes ago Up 22 minutes (healthy)
harbor-log goharbor/harbor-log:v2.7.1 "/bin/sh -c /usr/loc…" log 22 minutes ago Up 22 minutes (healthy) 127.0.0.1:1514->10514/tcp
harbor-portal goharbor/harbor-portal:v2.7.1 "nginx -g 'daemon of…" portal 22 minutes ago Up 22 minutes (healthy)
nginx goharbor/nginx-photon:v2.7.1 "nginx -g 'daemon of…" proxy 22 minutes ago Up 22 minutes (healthy) 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp
redis goharbor/redis-photon:v2.7.1 "redis-server /etc/r…" redis 22 minutes ago Up 22 minutes (healthy)
registry goharbor/registry-photon:v2.7.1 "/home/harbor/entryp…" registry 22 minutes ago Up 22 minutes (healthy)
registryctl goharbor/harbor-registryctl:v2.7.1 "/home/harbor/start.…" registryctl 22 minutes ago Up 22 minutes (healthy)
第5步:浏览器里访问
主机ip+端口号,访问网站,登录harbor。
1.默认的登录的用户名和密码
admin
Harbor12345
2.新建一个项目,新建一个用户。

第6步:在另外一台docker宿主机上使用这个仓库
[root@docker harbor]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries" : ["192.168.102.136:8089"]
}
重启docker
[root@docker1 ~]# systemctl daemon-reload
[root@docker1 ~]# systemctl restart docker
第7步:修改镜像的名字。
[root@docker harbor]# docker tag nginx:latest 192.168.102.136:8089/sanchuang/nginx:latest
[root@docker harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.102.136:8089/sanchuang/nginx latest 904b8cb13b93 2 weeks ago 142MB
第8步:本宿主机上传镜像
使用wei这个用户登录私有库。(wei用户密码是自己设置的)
[root@docker harbor]# docker login 192.168.102.136:8089
Username: wei
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
第9步:把镜像推送到harbo
[root@docker harbor]# docker push 192.168.102.136:8089/sanchuang/nginx:latest
The push refers to repository [192.168.102.136:8089/sanchuang/nginx]
101af4ba983b: Pushed
d8466e142d87: Pushed
83ba6d8ffb8c: Pushed
e161c82b34d2: Pushed
4dc5cd799a08: Pushed
650abce4b096: Pushed
latest: digest: sha256:942ae2dfd73088b54d7151a3c3fd5af038a51c50029bfcfd21f1e650d9579967 size: 1570
登录harbor查看是否推送成功。

第10步:测试
删除本机的镜像,去harbor仓库里拉取。
[root@docker harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.102.136:8089/sanchuang/nginx latest 904b8cb13b93 2 weeks ago 142MB
[root@docker harbor]# docker rmi 192.168.102.136:8089/sanchuang/nginx
Untagged: 192.168.102.136:8089/sanchuang/nginx:latest
Untagged: 192.168.102.136:8089/sanchuang/nginx@sha256:942ae2dfd73088b54d7151a3c3fd5af038a51c50029bfcfd21f1e650d9579967
[root@docker harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@docker harbor]# docker pull 192.168.102.136:8089/sanchuang/nginx:latest
latest: Pulling from sanchuang/nginx
Digest: sha256:942ae2dfd73088b54d7151a3c3fd5af038a51c50029bfcfd21f1e650d9579967
Status: Downloaded newer image for 192.168.102.136:8089/sanchuang/nginx:latest
192.168.102.136:8089/sanchuang/nginx:latest
[root@docker harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.102.136:8089/sanchuang/nginx latest 904b8cb13b93 2 weeks ago 142MB
关闭harbor
[root@docker harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9b148a747068 goharbor/harbor-jobservice:v2.7.1 "/harbor/entrypoint.…" 6 hours ago Up 27 seconds (health: starting) harbor-jobservice
c2589edcf518 goharbor/nginx-photon:v2.7.1 "nginx -g 'daemon of…" 6 hours ago Up 29 seconds (health: starting) 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp nginx
a624920adf44 goharbor/harbor-core:v2.7.1 "/harbor/entrypoint.…" 6 hours ago Up 28 seconds (health: starting) harbor-core
7ece59296f0e goharbor/harbor-db:v2.7.1 "/docker-entrypoint.…" 6 hours ago Up 29 seconds (health: starting) harbor-db
0369aca4d8ee goharbor/registry-photon:v2.7.1 "/home/harbor/entryp…" 6 hours ago Up 28 seconds (health: starting) registry
68b4a72d00cf goharbor/harbor-portal:v2.7.1 "nginx -g 'daemon of…" 6 hours ago Up 30 seconds (healthy) harbor-portal
6d743f459650 goharbor/harbor-registryctl:v2.7.1 "/home/harbor/start.…" 6 hours ago Up 29 seconds (health: starting) registryctl
1c9dbe7c9c71 goharbor/redis-photon:v2.7.1 "redis-server /etc/r…" 6 hours ago Up 29 seconds (health: starting) redis
507109bae338 goharbor/harbor-log:v2.7.1 "/bin/sh -c /usr/loc…" 6 hours ago Up 30 seconds (healthy) 127.0.0.1:1514->10514/tcp harbor-log
[root@docker harbor]# pwd
/lianxi/Dockerfile/harbor/harbor
使用docker compose stop
[root@docker harbor]# docker compose stop
[+] Running 9/9
⠿ Container registryctl Stopped 10.2s
⠿ Container harbor-jobservice Stopped 0.2s
⠿ Container nginx Stopped 0.2s
⠿ Container harbor-core Stopped 3.1s
⠿ Container harbor-portal Stopped 0.2s
⠿ Container redis Stopped 0.3s
⠿ Container harbor-db Stopped 0.3s
⠿ Container registry Stopped 0.2s
⠿ Container harbor-log Stopped
10.2s
[root@docker harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES