前言:Harbor 是 Vmwar 公司开源的 企业级的 Docker Registry 管理项目
它主要 提供 Dcoker Registry 管理UI,可基于角色访问控制, AD/LDAP 集成,日志审核等功能,完全的支持中文
Harbor 的所有组件都在 Dcoker 中部署,所以 Harbor 可使用 Docker Compose 快速部署。
这些参数对于更新是可选的,即用户可以将其保留为默认值,并在启动 Harbor 后在 Web UI 上进行更新
如果进入 Harbor.cfg,只会在第一次启动 Harbor 时生效,随后对这些参数 的更新,Harbor.cfg 将被忽略
注意:如果选择通过UI设置这些参数,请确保在启动Harbour后立即执行此操作。具体来说,必须在注册或在Harbor 中创建任何新用户之前设置所需的auth_mode。当系统中有用户时(除了默认的 admin 用户),auth_mode 不能被修改
具体参数如下:
另外,默认情况下,Harbour 将镜像存储在本地文件系统上。在生产环境中,可以考虑 使用其他存储后端而不是本地文件系统,
如 S3、Openstack Swif、Ceph 等。但需要更新 common/templates/registry/config.yml 文件
[root@promote harbor]# cd /usr/local/bin/
[root@promote bin]# ls
docker-compose
[root@promote bin]# docker-compose -v //查看版本判断安装是否成功
docker-compose version 1.21.1, build 5a3f1a3
wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
[root@promote opt]# ls
harbor-offline-installer-v1.2.2.tgz
[root@promote opt]# tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
hostname = 192.168.170.132 //需要写IP地址或者域名
ui_url_protocol = http //用于访问UI令牌/通知服务的协议
db_password = root123 //mysql数据库root密码
max_job_workers = 3 //镜像复制作业线程
customize_crt = on //用于生成/验证注册表令牌
ssl_cert = /data/cert/server.crt //证书路径,没有目录需要创建
ssl_cert_key = /data/cert/server.key //密钥路径,没有目录需要创建
secretkey_path = /data //register密钥路径
admiral_url = NA
clair_db_password = password
#************************BEGIN INITIAL PROPERTIES************************
email_identity =
email_server = smtp.mydomain.com
email_server_port = 25
email_username = [email protected]
email_password = abc
harbor_admin_password = Harbor12345 //Harbor登录密码
auth_mode = db_auth
ldap_url = ldaps://ldap.mydomain.com
ldap_basedn = ou=people,dc=mydomain,dc=com
ldap_uid = uid
ldap_scope = 3
ldap_timeout = 5
self_registration = on
token_expiration = 30
project_creation_restriction = everyone
verify_remote_cert = on
[root@promote opt]# sh /usr/local/harbor/install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.8
Note: docker-compose version: 1.21.1
[Step 1]: loading Harbor images ...
dd60b611baaa: Loading layer
。。。省略部分内容
[Step 2]: preparing environment ...
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[Step 3]: checking existing instance of Harbor ...
[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-adminserver ... done
Creating harbor-db ... done
Creating registry ... done
Creating harbor-ui ... done
Creating nginx ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.170.132.
For more details, please visit https://github.com/vmware/harbor .
[root@promote bin]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-log v1.2.2 36ef78ae27df 2 years ago 200MB
vmware/harbor-jobservice v1.2.2 e2af366cba44 2 years ago 164MB
vmware/harbor-ui v1.2.2 39efb472c253 2 years ago 178MB
vmware/harbor-adminserver v1.2.2 c75963ec543f 2 years ago 142MB
vmware/harbor-db v1.2.2 ee7b9fa37c5d 2 years ago 329MB
vmware/nginx-photon 1.11.13 6cc5c831fc7f 2 years ago 144MB
vmware/registry 2.6.2-photon 5d9100e4350e 2 years ago 173MB
vmware/postgresql 9.6.4-photon c562762cbd12 2 years ago 225MB
vmware/clair v2.0.1-photon f04966b4af6c 2 years ago 297MB
vmware/harbor-notary-db mariadb-10.1.10 64ed814665c6 3 years ago 324MB
vmware/notary-photon signer-0.5.0 b1eda7d10640 3 years ago 156MB
vmware/notary-photon server-0.5.0 6e2646682e3c 3 years ago 157MB
photon 1.0 e6e4e4a2ba1b 3 years ago 128MB
[root@promote bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ee73887363e vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" 3 minutes ago Up 3 minutes harbor-jobservice
af1dcf1a3620 vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
2f535eaff0b5 vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" 3 minutes ago Up 3 minutes harbor-ui
b70afcf6553d vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp harbor-db
61521edc3571 vmware/registry:2.6.2-photon "/entrypoint.sh serv…" 3 minutes ago Up 3 minutes 5000/tcp registry
5fe3a34f685d vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" 3 minutes ago Up 3 minutes harbor-adminserver
b556a7a38cdd vmware/harbor-log:v1.2.2 "/bin/sh -c 'crond &…" 3 minutes ago Up 3 minutes 127.0.0.1:1514->514/tcp harbor-log
[root@promote bin]# cd /usr/local/harbor/
[root@promote harbor]# docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
harbor-jobservice /harbor/harbor_jobservice Up
harbor-log /bin/sh -c crond && rm -f ... Up 127.0.0.1:1514->514/tcp
harbor-ui /harbor/harbor_ui Up
nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp,
0.0.0.0:80->80/tcp
registry /entrypoint.sh serve /etc/ ... Up 5000/tcp
[root@promote harbor]# docker login -uadmin -pHarbor12345 http://127.0.0.1 //本地登录
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@promote harbor]# docker pull cirros //下载镜像
Using default tag: latest
latest: Pulling from library/cirros
f513001ba4ab: Pull complete
8da581cc9286: Pull complete
856628d95d17: Pull complete
Digest: sha256:21874a9fd73378a29345163e026bc9c2a61aef62526f2b4f22a5d488059970f6
Status: Downloaded newer image for cirros:latest
docker.io/library/cirros:latest
[root@promote harbor]# docker tag cirros:latest 127.0.0.1/xiangmu/cirros:v1 //打上标签
[root@promote harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1/xiangmu/cirros v1 3c82e4d066cf 6 weeks ago 12.6MB
cirros latest 3c82e4d066cf 6 weeks ago 12.6MB
[root@promote harbor]# docker push 127.0.0.1/xiangmu/cirros:v1
The push refers to repository [127.0.0.1/xiangmu/cirros]
858d98ac4893: Layer already exists
aa107a407592: Layer already exists
b993cfcfd8fd: Layer already exists
v1: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943
[root@promote ~]# docker login -uadmin -pHarbor12345 http://192.168.170.132
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.170.132/v2/: dial tcp 192.168.170.132:443: connect: connection refused
[root@promote ~]# vim /usr/lib/systemd/system/docker.service
14 ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.170.132 --containerd=/run/containerd/containerd.sock
//在中间添加 --insecure-registry 192.168.170.132
[root@promote ~]# systemctl daemon-reload
[root@promote ~]# systemctl restart docker //重启服务
[root@promote ~]# docker login -uadmin -pHarbor12345 http://192.168.170.132
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@promote ~]# docker tag cirros:latest 192.168.170.132/xiangmu/cirros:v2
[root@promote ~]# docker push 192.168.170.132/xiangmu/cirros:v2
The push refers to repository [192.168.170.132/xiangmu/cirros]
858d98ac4893: Layer already exists
aa107a407592: Layer already exists
b993cfcfd8fd: Layer already exists
v2: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943
//上传成功
[root@promote harbor]# pwd
/usr/local/harbor
[root@promote harbor]# docker-compose down -v //停止实例
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-ui ... done
Stopping harbor-db ... done
Stopping registry ... done
Stopping harbor-adminserver ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-ui ... done
Removing harbor-db ... done
Removing registry ... done
Removing harbor-adminserver ... done
Removing harbor-log ... done
Removing network harbor_harbor
[root@promote harbor]# ./prepare
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[root@promote harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db ... done
Creating registry ... done
Creating harbor-adminserver ... done
Creating harbor-ui ... done
Creating nginx ... done
Creating harbor-jobservice ... done
[root@promote harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-885bf3146a17 -j RETURN: iptables: No chain/target/match by that name.
(exit status 1))
[root@promote harbor]# systemctl restart docker
[root@promote docker]# docker logout http://192.168.170.132
Removing login credentials for 192.168.170.132
[root@promote docker]# docker login http://192.168.170.132
Username: chanze
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@promote docker]# docker images //此时没有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@promote docker]# docker pull 192.168.170.132/xiangmu/cirros:v1
v1: Pulling from xiangmu/cirros
f513001ba4ab: Pull complete
8da581cc9286: Pull complete
856628d95d17: Pull complete
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Downloaded newer image for 192.168.170.132/xiangmu/cirros:v1
192.168.170.132/xiangmu/cirros:v1 //下载完成
[root@promote docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.170.132/xiangmu/cirros v1 3c82e4d066cf 6 weeks ago 12.6MB
//持久数据,如镜像,数据库等在宿主机的/data/目录下,日志在宿主机的/var/log/Harbor目录下;需要停止服务
docker-compose down -v
rm -rf /data/database
rm -rf /data/registry
[root@promote harbor]# cd /var/log/harbor/ //harbor相关日志
[root@harbor harbor]# ls
2020-04-23 2020-04-24
[root@promote harbor]# cd /data/ //持久化数据,如镜像、数据库等在harbor的/data目录下
[root@promote data]# ls
ca_download config database job_logs psc registry secretkey
//如果删除持久化数据,需要先关闭容器
[root@promote data]# cd /usr/local/harbor
[root@promote data]# docker-compose down -v
[root@promote data]# rm -rf /data/database/ /data/registry/