理论+实操:harbor私有仓库


查看Docker-Compose版本(记得先把docker-compose复制到/usr/bin下)

docker-compose -v

一:harbor概述

Harbor被部署为多个Docker容器,因此可以部署在任何支持Docker的Linux发行版本上

服务端主机需要安装的环境有Python、Docker、和Docker-compose

在k8s中,harbor也会用

harbor是用项目来管理镜像的,这样便于管理

二:部署Harbor服务

环境如下:

两个主机都具备docker环境

第一台主机做私有仓库,第二台主机做客户端去进行访问验证

2.1 下载Harbor程序

[root@ct ~]# hostnamectl set-hostname harbor
[root@ct ~]# su
[root@harbor ~]# 
[root@harbor ~]# yum install wget -y;wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
Installed:
  wget.x86_64 0:1.14-18.el7_6.1               
Complete!
http://: Invalid host name.
--2020-04-24 08:25:14--  http://harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
Resolving harbor.orientsoft.cn (harbor.orientsoft.cn)... 118.123.5.23
Connecting to harbor.orientsoft.cn (harbor.orientsoft.cn)|118.123.5.23|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 533765727 (509M) [application/octet-stream]
Saving to: ‘harbor-offline-installer-v1.2.2.tgz’

 7% [===========>                                                                                                                                                          ] 40,427,592  1.13MB/s  eta 6m 59s 

等一会,这个软件500多M,不想下载的m我

Total wall clock time: 7m 34s
Downloaded: 1 files, 509M in 7m 34s (1.12 MB/s)
You have new mail in /var/spool/mail/root
[root@harbor ~]# 
[root@harbor ~]# ls
anaconda-ks.cfg  compose_nginx  consul  consul-template_0.19.3_linux_amd64.zip  harbor-offline-installer-v1.2.2.tgz  perl5

解压

[root@harbor ~]# tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/

2.2 查看harbor参数文件

关于Harbor.cfg配置文件中被分为两种参数:所需参数和可选参数

  • 所需参数

这些参数必须在安装前进行设置,如果管理者想要更新他们,必须在改完参数之后再次安装,参数才会生效

  • 可选参数

这些参数对于更新时可选的,即管理者可以将其保留为默认值,在启动后可以在web端上进行修改更新

如果进入harbor.cfg,只会在第一次启动Harbor时生效,随后对这些参数的更新,Harbor将被忽略

备注:

如果选择通过WEB设置这些参数,必须得在启动Habor后只有admin这个管理员用户的情况下操作;当harbor中有除了admin之外的用户时,auth_mode不能被修改;所以,设置参数要趁早

[root@harbor ~]# cd /usr/local/harbor/
[root@harbor harbor]# ls
common  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  harbor_1_1_0_template  harbor.cfg  harbor.v1.2.2.tar.gz  install.sh  LICENSE  NOTICE  prepare  upgrade
[root@harbor harbor]# vim /usr/local/harbor/harbor.cfg

全部配置文件参数如下,解释性英文我会将其翻译

## 配置文件Harbor

#访问管理用户界面和注册表服务的IP地址或主机名。
#不要使用localhost或127.0.0.1,因为Harbor需要由外部客户机访问。
hostname = reg.mydomain.com

#用于访问UI和令牌/通知服务的协议,默认情况下是http。
#如果在nginx上启用了ssl,则可以将其设置为https。
ui_url_protocol = http

#mysql db的db_auth的根用户的密码,在任何生产使用之前更改,mysql db内存放的是用户验证信息,当用户登录时的账号密码会与mysql的内容进行比对,如果正确,就会给用户一个30分钟的临时令牌token
db_password = root123

#镜像复制作业线程最大数量。
max_job_workers = 3 

#确定是否为注册中心的令牌生成证书。
#如果该值为on,那么prepare脚本将创建新的根证书和私钥,以生成访问注册中心的令牌。如果该值为off,则使用默认的密钥/证书,也可以指定外部来源的根证书/密钥
#此标志还控制公证员证书的创建。
customize_crt = on

#nginx的cert和密钥文件的路径,它们只应用于协议设置为https
ssl_cert = /data/cert/server.crt
#证书的路径,仅当协议设置为 https 时才应用。
ssl_cert_key = /data/cert/server.key
#密钥的路径,仅当协议设置为 https 时才应用。

#密钥存储的路径,用于在复制策略中加密或解密远程 register 密码的密钥路径。
secretkey_path = /data

#Admiral's url, 注释此属性, or 将其值设置为NA when Harbor is 独立
admiral_url = NA

#Clair的postgres数据库的密码,只有在使用Clair部署Harbor时才有效。
#请在部署之前更新它,后续更新将导致Clair的API服务器和Harbor无法访问Clair的数据库。
clair_db_password = password

#注意:开始初始属性和结束初始属性之间的属性只在第一次引导时生效,这些属性的后续更改应该在web ui上执行

#开始初始属性,即可选参数,此处为分界线,上面是所需参数

#电子邮件帐户设置发送密码重置电子邮件。

#电子邮件服务器使用给定的用户名和密码在到主机的TLS连接上进行身份验证并充当身份。
#身份留空作为用户名。
email_identity = 
#Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。
#请注意,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但不支持STARTTLS
#那么应该通过设置启用SSL email_ssl = TRUE。
email_server = smtp.mydomain.com
email_server_port = 25
email_username = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
email_ssl = false

##Harbor管理员的初始密码,只有在Harbor启动时才有效。
#在第一次启动之后就没有效果了
#启动后从用户界面更改管理员密码。默认的用户名/密码是 admin/Harbor12345。
harbor_admin_password = Harbor12345

##默认情况下,验证模式是db_auth,即凭据存储在本地数据库中。
#如果希望根据LDAP服务器验证用户的凭据,请将其设置为ldap_auth。
auth_mode = db_auth

#ldap端点的url。
ldap_url = ldaps://ldap.mydomain.com

# 具有搜索LDAP/AD服务器权限的用户的DN。
#如果您的LDAP/AD服务器不支持匿名搜索,那么您应该配置这个DN和ldap_search_pwd。
#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com

#ldap_searchdn的密码
#ldap_search_pwd = password

#用来在LDAP/AD中查找用户的基本DN
ldap_basedn = ou=people,dc=mydomain,dc=com

#搜索LDAP/AD筛选器,确保筛选器的语法正确。
#ldap_filter = (objectClass=person)

#  在搜索中用于匹配用户的属性可以是uid、cn、电子邮件、sAMAccountName或其他属性(取决于您的LDAP/AD)
ldap_uid = uid 

#搜索用户的范围,1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREE
ldap_scope = 3 

#连接LDAP服务器时的超时(以秒为单位)。默认值(也是最合理的)是5秒。
ldap_timeout = 5

#打开或关闭自注册功能;禁用时,新用户只能由 Admin 用户创建
#只有管理员用户可以在 Harbour中创建新用户。
#注意:当 auth_mode 设置为 ldap_auth 时,自注册功能将始终处于禁用状态,并且该标志被忽略。
self_registration = on

#令牌服务创建的令牌过期时间(分钟),默认为30分钟
token_expiration = 30

#用于控制哪些用户具有创建项目的权限的标志
#默认值“everyone”允许每个人创建一个项目。
#设置为“adminonly”,只有管理员用户可以创建项目。
project_creation_restriction = everyone

#确定作业服务在连接到远程注册中心时是否应验证ssl证书。
#当远程注册中心使用自签名或不受信任的证书时,将此标志设置为off,将绕过 SSL/TLS 验证,这在远程实例具有自签名或不可信证书时经常使用。
verify_remote_cert = on
#************************结束初始属性************************
#############

另外,默认情况下,Harbour 将镜像存储在本地文件系统上。在生产环境中,可以考虑 使用其他存储后端而不是本地文件系统,

如 S3、Openstack Swif、Ceph 等。但需要更新 common/templates/registry/config.yml 文件。

  • docker-compose.yml其中写了多个容器的编排,有的容器还会挂载物理卷以提供存储备份

这个文件里面写了多个容器的编排,比如

其中有仓库镜像,挂载了物理卷

log日志容器,

还会装一个mysql数据库,镜像信息都会放在里面

jobservice 服务端

proxy 代理端

这些容器之间都会共享一个网络命名空间

  • 查看install.sh

使用install.sh去调用docker-compose-yml文件。yml文件去出发多个容器的编排执行,创建多个容器

2.3 安装harbor

初次安装,发现报错,发现没有修改hostname

[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# sh /usr/local/harbor/install.sh
➜ Please set hostname and other necessary attributes in harbor.cfg first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.cfg bacause notary must run under https. 
Please set --with-clair if needs enable Clair in Harbor
[root@harbor harbor]# sed -i '/^hostname/ s/hostname = reg.mydomain.com/hostname = 192.168.247.20/' /usr/local/harbor/harbor.cfg 
[root@harbor harbor]# sh /usr/local/harbor/install.sh

再次安装,又发现报错,原因是80端口被占用,原始环境内有多余的容器或者服务占用

ERROR: for nginx  Cannot start service proxy: b'driver failed programming external connectivity on endpoint nginx (ef804df0145f484c650f62919d3b873d45d5da2e48e4af7288a9918f64978f10): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'

ERROR: for proxy  Cannot start service proxy: b'driver failed programming external connectivity on endpoint nginx (ef804df0145f484c650f62919d3b873d45d5da2e48e4af7288a9918f64978f10): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'
ERROR: Encountered errors while bringing up the project.
[root@harbor harbor]# netstat -natp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      77583/nginx: master 

关闭80端口的服务,解除占用,重新执行

[root@harbor harbor]# ps aux | grep nginx
root      13972  0.0  0.0  15808  5520 ?        Sl   Apr23   0:03 consul-template -consul-addr 192.168.247.20:8500 -template /root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/gsy.conf:/usr/local/nginx/sbin/nginx -s reload --log-level=info
root      40235  0.0  0.0 112712   956 pts/2    R+   09:42   0:00 grep --color=auto nginx
root      77583  0.0  0.0  20640  1452 ?        Ss   Apr23   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    90426  0.0  0.0  21036  1720 ?        S    Apr23   0:00 nginx: worker process
[root@harbor harbor]# kill 77583
bash: kill: (77583) - No such process
[root@harbor harbor]# kill 90426
bash: kill: (90426) - No such process
[root@harbor harbor]# ps aux | grep nginx
root      13972  0.0  0.0  15808  5520 ?        Sl   Apr23   0:03 consul-template -consul-addr 192.168.247.20:8500 -template /root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/gsy.conf:/usr/local/nginx/sbin/nginx -s reload --log-level=info
root      40975  0.0  0.0 112716   960 pts/2    S+   09:43   0:00 grep --color=auto nginx
[root@harbor harbor]# kill 13972
[root@harbor harbor]# ps aux | grep nginx
root      13972  0.0  0.0  15808  5520 ?        Sl   Apr23   0:03 consul-template -consul-addr 192.168.247.20:8500 -template /root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/gsy.conf:/usr/local/nginx/sbin/nginx -s reload --log-level=info
root      41407  0.0  0.0 112716   960 pts/2    S+   09:43   0:00 grep --color=auto nginx
[root@harbor harbor]# netstat -natp | grep 80
[root@harbor harbor]# 
[root@harbor harbor]# sh /usr/local/harbor/install.sh
✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://192.168.247.20. 
For more details, please visit https://github.com/vmware/harbor .

成功

备注:还要记得要有docker-compose环境

查看镜像容器

[root@harbor harbor]# docker ps -a
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
ba7d9a375058        vmware/harbor-jobservice:v1.2.2    "/harbor/harbor_jobs…"   3 minutes ago       Up 3 minutes                                                                           harbor-jobservice
9b35dc6e0254        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
5c483c62827f        vmware/harbor-ui:v1.2.2            "/harbor/harbor_ui"      3 minutes ago       Up 3 minutes                                                                           harbor-ui
abe4e1a49daf        vmware/harbor-db:v1.2.2            "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes        3306/tcp                                                           harbor-db
e04107e79018        vmware/registry:2.6.2-photon       "/entrypoint.sh serv…"   3 minutes ago       Up 3 minutes        5000/tcp                                                           registry
c9cc9f79eea7        vmware/harbor-adminserver:v1.2.2   "/harbor/harbor_admi…"   3 minutes ago       Up 3 minutes                                                                           harbor-adminserver
d59c77c80b46        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@harbor harbor]# dpcker images
bash: dpcker: command not found
[root@harbor harbor]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
compose_nginx_nginx         latest              e3abfd076454        2 days ago          726MB
centos                      7                   5e35e350aded        5 months ago        203MB
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

postgresql是mysql的内核,也是一个数据库

阿里云的镜像私有仓库可以了解一下

在这里插入图片描述

三:管理Harbor仓库

3.1 登录web端

此时便可以登录web端,访问80端口

在这里插入图片描述

账号密码(第一次登录)默认为:admin Harbor12345

在这里插入图片描述

此时其中有一个默认的项目libary,用户身份时admin,可以创建用户,创建项目

在这里插入图片描述

LDAP是目录模式验证

3.2 查看harbor相关容器

[root@harbor 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                                                        

备注:这条名字只能在/usr/local/harbor/下操作

[root@harbor harbor]# cd -
/root
[root@harbor ~]# docker-compose ps
ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml

3.3 可以在本地终端使用docker push上传镜像

在本地通过 127.0.0.1 来登录和推送镜像。默认情况下, Register 服务器在端口 80 上侦听。

指定192.168.247.20也可以

先登录

[root@harbor ~]# docker login -u admin -p Harbor12345 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@harbor ~]# docker pull cirros
Status: Downloaded newer image for cirros:latest
[root@harbor ~]# docker images | grep cirros
cirros                      latest              3c82e4d066cf        6 weeks ago         12.6MB

接下来进行推送镜像到仓库内的操作

在这里插入图片描述

给其修改个标签

[root@harbor ~]# docker tag cirros:latest 192.168.247.20/gsy/cirros:vers1
[root@harbor ~]# docker images | grep cirros
192.168.247.20/gsy/cirros   vers1               3c82e4d066cf        6 weeks ago         12.6MB
cirros                      latest              3c82e4d066cf        6 weeks ago         12.6MB

然后上传,发现连接拒绝,因为没有给其指定路径,如何指定路径后面会提及

[root@harbor ~]# docker push 192.168.247.20/gsy/cirros:vers1
The push refers to repository [192.168.247.20/gsy/cirros]
Get https://192.168.247.20/v2/: dial tcp 192.168.247.20:443: connect: connection refused

指定127.0.0.1回环地址就可以直接上传

[root@harbor ~]# docker tag cirros:latest 127.0.0.1/gsy/cirros:vers1
[root@harbor ~]# docker push 127.0.0.1/gsy/cirros:vers1
The push refers to repository [127.0.0.1/gsy/cirros]
858d98ac4893: Pushed 
aa107a407592: Pushed 
b993cfcfd8fd: Pushed 
vers1: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943

回到web界面查看情况

刷新下,出现镜像

在这里插入图片描述

在这里插入图片描述

复制粘贴这条命令可以从仓库内拉取镜像,结果出现报错

[root@harbor ~]# docker pull 192.168.247.20/gsy/cirros:vers1
Error response from daemon: Get https://192.168.247.20/v2/: dial tcp 192.168.247.20:443: connect: connection refused
[root@harbor ~]# 

查看当前本地镜像

[root@harbor ~]# docker images | grep cirros
192.168.247.20/gsy/cirros   vers1               3c82e4d066cf        6 weeks ago         12.6MB
cirros                      latest              3c82e4d066cf        6 weeks ago         12.6MB
127.0.0.1/gsy/cirros        vers1               3c82e4d066cf        6 weeks ago         12.6MB

先测试拉取127.0.0.1的,发现可以

[root@harbor ~]# docker pull 127.0.0.1/gsy/cirros:vers1
vers1: Pulling from gsy/cirros
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Image is up to date for 127.0.0.1/gsy/cirros:vers1
127.0.0.1/gsy/cirros:vers1

先删掉镜像再确认测试

[root@harbor ~]# docker rmi 127.0.0.1/gsy/cirros:vers1
Untagged: 127.0.0.1/gsy/cirros:vers1
Untagged: 127.0.0.1/gsy/cirros@sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
[root@harbor ~]# docker rmi 192.168.247.20/gsy/cirros:vers1
Untagged: 192.168.247.20/gsy/cirros:vers1
[root@harbor ~]# docker images | grep cirros
cirros                      latest              3c82e4d066cf        6 weeks ago         12.6MB
[root@harbor ~]# docker pull 127.0.0.1/gsy/cirros:vers1
vers1: Pulling from gsy/cirros
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Downloaded newer image for 127.0.0.1/gsy/cirros:vers1
127.0.0.1/gsy/cirros:vers1
[root@harbor ~]# docker pull 192.168.247.20/gsy/cirros:vers1
Error response from daemon: Get https://192.168.247.20/v2/: dial tcp 192.168.247.20:443: connect: connection refused
You have new mail in /var/spool/mail/root
[root@harbor ~]# docker images | grep cirros
127.0.0.1/gsy/cirros        vers1               3c82e4d066cf        6 weeks ago         12.6MB
cirros                      latest              3c82e4d066cf        6 weeks ago         12.6MB

发现此时以本地终端127.0.0.1的端口去上传拉取镜像都没问题,但是使用客户端身份的方式手段去拉取上传镜像会出现问题

四:使用客户端以admin身份去登录

[root@client ~]# docker login http://192.168.247.20
Username: admin
Password: 
Error response from daemon: Get https://192.168.247.20/v2/: dial tcp 192.168.247.20:443: connect: connection refused

也出现相同报错

出现这问题的原因 Docker Registry 交互默认使用的是 HTTPS,但是搭建私有镜

像默认使用的是 HTTP 服务

问题解决思路如下:

[root@client ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.247.20 --containerd=/run/containerd/containerd.sock
[root@client ~]# systemctl daemon-reload 
[root@client ~]#  systemctl restart docker

重新尝试,记得密码要输全

[root@client ~]# docker login http://192.168.247.20
Username: admin
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@client ~]# docker logout http://192.168.247.20
Removing login credentials for 192.168.247.20

此时先测试拉取镜像,成功

root@client ~]# docker pull 192.168.247.20/gsy/cirros:vers1
vers1: Pulling from gsy/cirros
f513001ba4ab: Pull complete 
8da581cc9286: Pull complete 
856628d95d17: Pull complete 
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Downloaded newer image for 192.168.247.20/gsy/cirros:vers1
192.168.247.20/gsy/cirros:vers1
[root@client ~]# 
[root@client ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
nginx                       latest              e791337790a6        6 days ago          127MB
httpd                       latest              bdc169d27d36        7 days ago          166MB
192.168.247.20/gsy/cirros   vers1               3c82e4d066cf        6 weeks ago         12.6MB
gliderlabs/registrator      latest              3b59190c6c80        4 years ago         23.8MB

上传镜像nginx

[root@client ~]# docker tag nginx:latest 192.168.247.20/gsy/vers1
[root@client ~]# docker push 192.168.247.20/gsy/vers1
The push refers to repository [192.168.247.20/gsy/vers1]
be91fceb796e: Pushed 
919b6770519b: Pushed 
b60e5c3bcef2: Pushed 
latest: digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee size: 948
[root@client ~]# 

到web查看

在这里插入图片描述

五:维护管理harbor——docker-compose

可以使用 docker-compose 来管理 Harbor。一些有用的命令如下所示,必须在与 docker-compose.yml 相同的目录中运行。

要更改 Harbor 的配置文件时,必须先停止现有的 Harbor 实例并更新 Harbor.cfg;然后运行 prepare 脚本来填充配置;最后重新创建并启动 Harbor 的实例。

5.1docker-compose down -v——此时容器全部关闭删除

[root@harbor 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@harbor harbor]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

5.2 然后编辑/usr/local/harbor/harbor/cfg

5.3 ./prepare重新填充配置

备注:使用harbor过程中,不要关闭防火墙,因为harbor需要用到防火墙的DNAT规则

[root@harbor harbor]# ./prepare 
#只能用./prepare,不能用sh prepare

此时容器还都未起来

[root@harbor harbor]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

5.4 docker-compose up -d——开启

[root@harbor harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry           ... done
Creating harbor-db          ... done
Creating harbor-adminserver ... done
Creating harbor-ui          ... done
Creating harbor-jobservice  ... done
Creating nginx              ... done
[root@harbor harbor]# docker ps -a
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
94630e81bb21        vmware/harbor-jobservice:v1.2.2    "/harbor/harbor_jobs…"   11 seconds ago      Up 10 seconds                                                                          harbor-jobservice
e68e275ba6c5        vmware/nginx-photon:1.11.13        "nginx -g 'daemon of…"   11 seconds ago      Up 10 seconds       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp   nginx
278c281594c9        vmware/harbor-ui:v1.2.2            "/harbor/harbor_ui"      11 seconds ago      Up 10 seconds                                                                          harbor-ui
b7adea7dfc28        vmware/registry:2.6.2-photon       "/entrypoint.sh serv…"   12 seconds ago      Up 11 seconds       5000/tcp                                                           registry
b587a5b5a4f9        vmware/harbor-db:v1.2.2            "docker-entrypoint.s…"   12 seconds ago      Up 11 seconds       3306/tcp                                                           harbor-db
8fbb66df3206        vmware/harbor-adminserver:v1.2.2   "/harbor/harbor_admi…"   12 seconds ago      Up 11 seconds                                                                          harbor-adminserver
b282d0c45952        vmware/harbor-log:v1.2.2           "/bin/sh -c 'crond &…"   12 seconds ago      Up 12 seconds       127.0.0.1:1514->514/tcp                                            harbor-log
[root@harbor harbor]# 

六:创建harbor用户

在web端可以创建用户
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

可以将用户添加到项目中

在这里插入图片描述

管理员当然权限最大,这里测试一下开发人员

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在客户端以gsy身份去登录,测试开发人员具有的权限

[root@client ~]# docker login http://192.168.247.20
Username: gsy
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@client ~]# docker tag nginx:latest 192.168.247.20/gsy/nginx:gsy1
[root@client ~]# docker push 192.168.247.20/gsy/nginx:gsy1
The push refers to repository [192.168.247.20/gsy/nginx]
be91fceb796e: Mounted from gsy/vers1 
919b6770519b: Mounted from gsy/vers1 
b60e5c3bcef2: Mounted from gsy/vers1 
gsy1: digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee size: 948

查看web
在这里插入图片描述

可以上传镜像,再测试拉取镜像

[root@client ~]# docker pull 192.168.247.20/gsy/nginx:gsy1
gsy1: Pulling from gsy/nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 192.168.247.20/gsy/nginx:gsy1
192.168.247.20/gsy/nginx:gsy1

也可以正常使用拉取镜像和上传镜像

七:迁移harbor数据

首先docker-compose down -v关闭Harbor仓库

然后拷贝harbor全部数据、持久数据,如镜像,数据库等在宿主机的/data/目录下,日志在宿主机的

/var/log/Harbor/目录下。

将数据直接拉取到目标服务器的对应路径下重新部署即可

/data/database/ 数据库内容,比如身份验证数据

/data/registry/ 镜像文件内容

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值