企业级镜像仓库Harbor

介绍:

Habor是由VMWare公司开源的容器镜像仓库。事实上,Habor是在Docker Registry上进行了相应的
企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访
问控制 ,AD/LDAP集成以及审计日志等,足以满足基本企业需求

组件     功能
harbor-adminserver 配置管理中心
harbor-db MySQL数据库
harbor-jobservice 负责镜像的复制
harbor-log 负责操作日志
harbor-ui Web管理页面和API
nginx 前端代理,负责前端页面和镜像的上传/下载转发
redis 会话
registry 镜像存储

Harbor的几种安装方式:

1、在线安装:从Docker Hub下载harbor相关镜像,因此安装软件包非常的小

2、离线安装:安装包包含部署的相关镜像,因此安装包比较大

3、OVA安装程序,当用户具有Vcenter环境的时候,使用此安装程序,再部署OVA后启动Harbor

这里我们使用离线安装的方式:

harbor-offline-installer-v1.6.1.tgz

tar -xf harbor-offline-installer-v1.6.1.tgz

修改配置文件

[root@hu-001 harbor]# grep -Ev "^$|^#" harbor.cfg_version = 1.6.0hostname = 192.168.20.11 #harbor 的地址,可以写IP,也可以写域名ui_url_protocol = httpmax_job_workers = 10customize_crt = onssl_cert = /data/cert/server.crtssl_cert_key = /data/cert/server.keysecretkey_path = /dataadmiral_url = NAlog_rotate_count = 50log_rotate_size = 200Mhttp_proxy =https_proxy =no_proxy = 127.0.0.1,localhost,ui,registryemail_identity =email_server = smtp.mydomain.comemail_server_port = 25email_username = sample_admin@mydomain.comemail_password = abcemail_from = admin <sample_admin@mydomain.com>email_ssl = falseemail_insecure = falseharbor_admin_password = 123456auth_mode = db_authldap_url = ldaps://ldap.mydomain.comldap_basedn = ou=people,dc=mydomain,dc=comldap_uid = uidldap_scope = 2ldap_timeout = 5ldap_verify_cert = trueldap_group_basedn = ou=group,dc=mydomain,dc=comldap_group_filter = objectclass=groupldap_group_gid = cnldap_group_scope = 2self_registration = ontoken_expiration = 30project_creation_restriction = everyonedb_host = postgresqldb_password = root123db_port = 5432db_user = postgresredis_host = redisredis_port = 6379redis_password =redis_db_index = 1,2,3clair_db_host = postgresqlclair_db_password = root123clair_db_port = 5432clair_db_username = postgresclair_db = postgresclair_updaters_interval = 12uaa_endpoint = uaa.mydomain.orguaa_clientid = iduaa_clientsecret = secretuaa_verify_cert = trueuaa_ca_cert = /path/to/ca.pemregistry_storage_provider_name = filesystemregistry_storage_provider_config =registry_custom_ca_bundle =

  

Harbor 是使用docker-compose来编排部署的,所以这里我们这里必须要有一个docker-compose

下载后就是一个二进制文件

docker-compose的作用是单机编排,以及管理多个容器

docker-compose-Linux-x86_64

mv docker-compose-Linux-x86_64 harbor/

mv docker-compose-Linux-x86_64 /usr/bin/docker-compose

chmod +x /usr/bin/docker-compose

[root@hu-001 harbor]# ./prepare   生成预配置文件

[root@hu-001 harbor]# ./install.sh 导入包中所有的镜像

[root@hu-001 harbor]# ./install.sh [Step 0]: checking installation environment ...Note: docker version: 18.09.0Note: docker-compose version: 1.23.1[Step 1]: loading Harbor images ...ad50e89f4922: Loading layer  133.4MB/133.4MB8c9a00a7f290: Loading layer  73.29MB/73.29MB078e22641f73: Loading layer  3.584kB/3.584kB5494f0d704cb: Loading layer  3.072kB/3.072kB34c7e304d18b: Loading layer  4.096kB/4.096kBae9209f78c11: Loading layer  3.584kB/3.584kB1498359f7391: Loading layer  9.728kB/9.728kBLoaded image: goharbor/harbor-log:v1.6.1bb738fd5b202: Loading layer  23.38MB/23.38MB51f6c7e046ae: Loading layer  21.15MB/21.15MB67ff79ae8340: Loading layer  21.15MB/21.15MBLoaded image: goharbor/harbor-jobservice:v1.6.1b5be864bae6a: Loading layer  83.89MB/83.89MB9fdbae37c606: Loading layer  3.072kB/3.072kBc24b06c70085: Loading layer   59.9kB/59.9kB946c040a69da: Loading layer  61.95kB/61.95kBLoaded image: goharbor/redis-photon:v1.6.1747ac74b0475: Loading layer  5.128MB/5.128MBLoaded image: goharbor/nginx-photon:v1.6.13d4aae33f4f1: Loading layer    683MB/683MB3cb271cda7e0: Loading layer   7.68kB/7.68kB7ae402931bdb: Loading layer  197.6kB/197.6kBLoaded image: goharbor/harbor-migrator:v1.6.167747a74e108: Loading layer  158.1MB/158.1MB93f3d22257c7: Loading layer  35.08MB/35.08MB2eda636f347b: Loading layer   2.56kB/2.56kB7a3b4ef015e8: Loading layer  35.08MB/35.08MBLoaded image: goharbor/chartmuseum-photon:v0.7.1-v1.6.1038c23438769: Loading layer  23.38MB/23.38MBa6a0201bf457: Loading layer  26.88MB/26.88MBaa0986b7d608: Loading layer  7.168kB/7.168kB830a350d7059: Loading layer  11.32MB/11.32MB3100afecce3d: Loading layer  26.87MB/26.87MBLoaded image: goharbor/harbor-ui:v1.6.115134eb6d277: Loading layer  95.85MB/95.85MB02cff5f31ca4: Loading layer  6.656kB/6.656kB3e43f3cb1d4c: Loading layer  2.048kB/2.048kB4ab1b74a5650: Loading layer   7.68kB/7.68kB9c78faccbd48: Loading layer   2.56kB/2.56kB158d4a16071f: Loading layer   2.56kB/2.56kB6a2fbfb6100b: Loading layer   2.56kB/2.56kBLoaded image: goharbor/harbor-db:v1.6.1b15fe66f326a: Loading layer  23.38MB/23.38MB336e69120569: Loading layer  3.072kB/3.072kBf308142e2037: Loading layer  3.072kB/3.072kB3119c7884a49: Loading layer  2.048kB/2.048kBfafa9955d095: Loading layer   22.8MB/22.8MB4c53b946082a: Loading layer   22.8MB/22.8MBLoaded image: goharbor/registry-photon:v2.6.2-v1.6.10fee5e457010: Loading layer  23.38MB/23.38MB6d1b402441fc: Loading layer  12.16MB/12.16MB765a288fcf5a: Loading layer   17.3MB/17.3MBda4578643aee: Loading layer  11.26kB/11.26kBf02d275fa76f: Loading layer  3.072kB/3.072kB4a3d1e973223: Loading layer  29.46MB/29.46MBLoaded image: goharbor/notary-server-photon:v0.5.1-v1.6.1918b224a19fd: Loading layer  10.95MB/10.95MBff41acdef199: Loading layer   17.3MB/17.3MB4389d5e9282a: Loading layer  11.26kB/11.26kB8a0e0bb6ed63: Loading layer  3.072kB/3.072kBd437ffa494e0: Loading layer  28.24MB/28.24MBLoaded image: goharbor/notary-signer-photon:v0.5.1-v1.6.11c86e9f19207: Loading layer  158.1MB/158.1MB3b4698fe61a0: Loading layer  10.93MB/10.93MB8dbd6d55a6cd: Loading layer  2.048kB/2.048kB5cb748f1dcf1: Loading layer  48.13kB/48.13kBf86a42ee549b: Loading layer  10.98MB/10.98MBLoaded image: goharbor/clair-photon:v2.0.6-v1.6.118abf81cd9fd: Loading layer  23.38MB/23.38MB66a3e670c5b5: Loading layer  15.58MB/15.58MB9cdd51a1e20c: Loading layer  15.36kB/15.36kB9aedba3496f1: Loading layer  15.58MB/15.58MBLoaded image: goharbor/harbor-adminserver:v1.6.1[Step 2]: preparing environment ...Clearing the configuration file: ./common/config/adminserver/envClearing the configuration file: ./common/config/ui/envClearing the configuration file: ./common/config/ui/app.confClearing the configuration file: ./common/config/ui/private_key.pemClearing the configuration file: ./common/config/db/envClearing the configuration file: ./common/config/jobservice/envClearing the configuration file: ./common/config/jobservice/config.ymlClearing the configuration file: ./common/config/registry/config.ymlClearing the configuration file: ./common/config/registry/root.crtClearing the configuration file: ./common/config/registryctl/envClearing the configuration file: ./common/config/registryctl/config.ymlClearing the configuration file: ./common/config/nginx/nginx.confClearing the configuration file: ./common/config/log/logrotate.confloaded secret from file: /data/secretkeyGenerated configuration file: ./common/config/nginx/nginx.confGenerated configuration file: ./common/config/adminserver/envGenerated configuration file: ./common/config/ui/envGenerated configuration file: ./common/config/registry/config.ymlGenerated configuration file: ./common/config/db/envGenerated configuration file: ./common/config/jobservice/envGenerated configuration file: ./common/config/jobservice/config.ymlGenerated configuration file: ./common/config/log/logrotate.confGenerated configuration file: ./common/config/registryctl/envGenerated configuration file: ./common/config/ui/app.confGenerated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crtThe 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 driverCreating harbor-log ... doneCreating registry           ... doneCreating harbor-db          ... doneCreating redis              ... doneCreating harbor-adminserver ... doneCreating harbor-ui          ... doneCreating harbor-jobservice  ... doneCreating nginx              ... done✔ ----Harbor has been installed and started successfully.----Now you should be able to visit the admin portal at http://192.168.20.11.For more details, please visit https://github.com/goharbor/harbor .

假如有什么异常的话,我们处理一下,然后使用docker-compose up -d 再启动一次

这个时候我们浏览器输入:

这里默认有一个项目是公开的

这个我们可以不用登陆就可以下载,但是我们上传的时候我们需要创建用户密码,所以这里我们在人员管理上添加一个用户,然后给这个项目分配成员

推送镜像的格式:

在项目中标记镜像:

  docker tag SOURCE_IMAGE[:TAG] 192.168.20.11/library/IMAGE[:TAG]

推送镜像到当前项目:  docker push 192.168.20.11/library/IMAGE[:TAG]

这里我们先标记镜像,然后把标记的镜像推送到Harbor 仓库中

在推送镜像之前我们需要先登录Harbor

默认是使用https方式的但是我们目前这里使用的事http的方式,所以这里我们要添加一个可信任的配置

[root@hu-001 harbor]# cat /etc/docker/daemon.json
{“registry-mirrors”: [“http://f1361db2.m.daocloud.io”],
“insecure-registries”:[“192.168.20.11”]
}

需要重启Docker才可以生效
systemctl restart docker

然后就是登录仓库(使用刚刚web页面上创建的用户名和密码)

[root@hu-001 harbor]# docker login 192.168.20.11 这里只要登录一次就可以了,但是会有失效时间,其实也不麻烦,每次上传的时候都可以登录一下Username: bigbaoPassword:WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

  

打标签docker tag nginx:1.15 192.168.20.11/library/bigbao_harbor_nginx:1.15上传镜像到仓库中[root@hu-001 harbor]# docker push 192.168.20.11/library/bigbao_harbor_nginx:1.15The push refers to repository [192.168.20.11/library/bigbao_harbor_nginx]ece4f9fdef59: Pushedad5345cbb119: Pushedef68f6734aa4: Pushed1.15: digest: sha256:87e9b6904b4286b8d41bba4461c0b736835fcc218f7ecbe5544b53fdd467189f size: 948
[root@hu-001 harbor]# docker imagesREPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE192.168.20.11/library/bigbao_harbor_nginx   1.15                568c4670fa80        4 days ago          109MBnginx                                       1.15                568c4670fa80        4 days ago          109MBnginx                                       latest              568c4670fa80        4 days ago          109MBgoharbor/chartmuseum-photon                 v0.7.1-v1.6.1       f0a2dbee1ff1        6 weeks ago         350MBgoharbor/harbor-migrator                    v1.6.1              60e8be845b35        6 weeks ago         798MBgoharbor/redis-photon                       v1.6.1              6a67380bb061        6 weeks ago         210MBgoharbor/clair-photon                       v2.0.6-v1.6.1       c4fcdbae7df2        6 weeks ago         302MBgoharbor/notary-server-photon               v0.5.1-v1.6.1       f1afd44d9f9b        6 weeks ago         209MBgoharbor/notary-signer-photon               v0.5.1-v1.6.1       83aa51867207        6 weeks ago         207MBgoharbor/registry-photon                    v2.6.2-v1.6.1       f4cb5e83f0a4        6 weeks ago         196MBgoharbor/nginx-photon                       v1.6.1              9ca888fe33b2        6 weeks ago         132MBgoharbor/harbor-log                         v1.6.1              9b1ea3f29465        6 weeks ago         198MBgoharbor/harbor-jobservice                  v1.6.1              9ca6fd371ca6        6 weeks ago         192MBgoharbor/harbor-ui                          v1.6.1              305ee5b8952c        6 weeks ago         215MBgoharbor/harbor-adminserver                 v1.6.1              a3e95f74984e        6 weeks ago         181MBgoharbor/harbor-db                          v1.6.1              3bea3bff0190        6 weeks ago         219MBcentos                                      7                   75835a67d134        7 weeks ago         200MBbusybox                                     latest              59788edf1f3e        2 months ago        1.15MB[root@hu-001 harbor]# docker tag centos:7 192.168.20.11/library/bigbao_harbor_centos:7[root@hu-001 harbor]# docker tag busybox:latest 192.168.20.11/library/bigbao_harbor_busybox:latest[root@hu-001 harbor]# docker push 192.168.20.11/library/bigbao_harbor_busybox:latestThe push refers to repository [192.168.20.11/library/bigbao_harbor_busybox]8a788232037e: Pushedlatest: digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527[root@hu-001 harbor]# docker push 192.168.20.11/library/bigbao_harbor_centos:7The push refers to repository [192.168.20.11/library/bigbao_harbor_centos]f972d139738d: Pushed7: digest: sha256:dc29e2bcceac52af0f01300402f5e756cc8c44a310867f6b94f5f7271d4f3fec size: 529

这个时候我们去看一下我们的镜像仓库就要镜像了

之前我们都是懂官方仓库下载镜像或者加速仓库下载,这个时候我们就可以从自己的私有仓库下载了

这里我们就可以直接只用

docker  pull 192.168.20.11/library/bigbao_harbor_centos:7 下载了(如果不是公开项目我们先登录)