docker私有镜像仓库harbor搭建和配置

安装前提:宿主机安装有docker

下载安装包

下载地址:github https://github.com/vmware/harbor/releases
解压之后,进入harbor目录,打开 harbor.cfg文件 ,所有配置详情如下,其中必选参数已加粗,原有注释表示还不知道啥意思 =-=!后续再慢慢补充

#harbor版本信息
_version = 1.6.0
#目标主机的主机名,不能用localhost和127.0.0.1	
**hostname = 47.107.178.206**
#(http或https,默认为http)用于访问UI和令牌/通知服务的协议。如果启用了认证,则此参数必须为https
**ui_url_protocol = http**
#作业服务中的最大复制工作数,增加此数量可以在系统中实现更多并发复制作业。
**max_job_workers = 10** 
#在准备脚本创建注册表的令牌是否生成/验证私钥和根证书,on表示生成,如果外部提供则设置为off
**customize_crt = on**

#The path of cert and key files for nginx, they are applied only the protocol is set to https
#证书和密钥的路径,仅在协议为https时应用
**ssl_cert = /data/cert/server.crt
   ssl_cert_key = /data/cert/server.key**

#加密或解密复制策略中远程注册表密码的密钥路径。
**secretkey_path = /data**

#Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone
admiral_url = NA

#日志文件在被删除之前会被轮询log_rotate_count次数,如果count为0,则删除旧版本而不是轮询。
log_rotate_count = 50
#单个日志文件最大值,只有大于该值才会轮换日志
log_rotate_size = 200M

#Config http proxy for Clair, e.g. http://my.proxy.com:3128
#Clair doesn't need to connect to harbor ui container via http proxy.
http_proxy =
https_proxy =
no_proxy = 127.0.0.1,localhost,ui,registry

 #邮件设置,发送重置密码邮件时使用
email_identity = 
email_server = smtp.mydomain.com
email_server_port = 25
email_username = [email protected]
email_password = abc
email_from = admin <[email protected]>
email_ssl = false
email_insecure = false

#默认admin账户的密码
harbor_admin_password = Harbor12345

 #认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证
auth_mode = db_auth

 #LDAP认证时配置项 需要是再配置,一般默认就行
ldap_url = ldaps://ldap.mydomain.com
ldap_basedn = ou=people,dc=mydomain,dc=com
ldap_uid = uid 
ldap_scope = 2 
ldap_timeout = 5
ldap_verify_cert = true
ldap_group_basedn = ou=group,dc=mydomain,dc=com
ldap_group_filter = objectclass=group
ldap_group_gid = cn
ldap_group_scope = 2

#是否开启自注册
self_registration = on

   #Token有效时间,默认30分钟
token_expiration = 30

 #用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员)
project_creation_restriction = everyone

db_host = postgresql
db_password = root123
db_port = 5432
db_user = postgres

#redis数据库连接信息
redis_host = redis
redis_port = 6379
redis_password = 
redis_db_index = 1,2,3

clair_db_host = postgresql
clair_db_password = root123
clair_db_port = 5432
clair_db_username = postgres
clair_db = postgres
clair_updaters_interval = 12

uaa_endpoint = uaa.mydomain.org
uaa_clientid = id
uaa_clientsecret = secret
uaa_verify_cert = true
uaa_ca_cert = /path/to/ca.pem

registry_storage_provider_config =

然后本目录执行 ./install.sh安装。安装过程中会拉取所需要的镜像。

push镜像

安装完成之后就可以push镜像到私有仓库了
我在另一台服务器上有一个简单的基于java的镜像,首先给该镜像打上标签

 docker tag 3e98ef625216 47.107.178.206/my_registry/my_jar_test:1

然后,我在这台服务器上登录另一台服务器搭建的Harbor仓库,docker login xxxxx
在这里插入图片描述
报错了,原来是这台服务器没有设置docker的远程Harbor仓库
打开 /usr/lib/systemd/system/docker.service 文件
在这项配置后面加上指向Harbor仓库的配置

ExecStart=/usr/bin/dockerd  --insecure-registry 47.107.178.206

或者修改etc/docker/daemon.json文件,添加registry-mirrors配置项,该项以为不安全的仓库。

"insecure-registries": ["172.16.xxx.xx","IP:PORT"],

再次登录就可成功了,push镜像

docker push 47.107.178.206/my_registry/my_jar_test:1

再换一台服务器拉镜像 :)

参考几篇较详细,介绍的比较深的博客
https://blog.csdn.net/teledcos/article/details/79730138
https://blog.csdn.net/aixiaoyang168/article/details/73549898
https://www.cnblogs.com/itzgr/p/10198641.html

猜你喜欢

转载自blog.csdn.net/zgq_hw/article/details/88045670