Docker(五)镜像仓库Harbor

docker镜像仓库Harbor

harbor介绍

Harbor为Vmware公司基于docker-distribution二次开发的镜像仓库,harbor意思为港口或者港湾;港口是用来停放集装箱的,而集装箱呢?提到集装箱就不得不想起容器了;上面说了港口使用来停放集装箱的,港口是Harbor,集装箱是Docker,那么Harbor就是用于存储Docker镜像的。
Project Harbor是一个开源可信云本机注册表项目,用于存储,签名和扫描内容.。
Harbor通过添加用户通常需要的功能(如安全性,身份和管理)来扩展开源Docker Distrbution。
Harbor支持高级功能,例如用户管理,访问控制,活动监控以及实例之间的复制。

harbor特性

  • 多租户内容签名和验证
  • 安全性和漏洞分析
  • 审核日志
  • 身份集成和基于角色的访问控制
  • 实例之间的映像复制
  • 可扩展的API和图形用户界面
  • 国际化(目前是英文和中文)
    为什么支持中文,因为VMware harbor团队大多数是国人所研发,嘻嘻,骄傲

harbor和docker registry比较

Harbor和Registry都是Docker镜像仓库,但为什么企业都选用Harbor呢?
以下说明Harbor的优势

  1. 提供镜像分层传输机制,优化网络传输
  2. 提供WEB界面,优化用户体验
  3. 支持水平扩展集群
  4. 良好的安全机制
  5. Harbor提供了基于角色访问控制机制,并通过项目来对镜像进行组织和访问权限的控制

harbor架构

Docker(五)镜像仓库Harbor_第1张图片

proxy:Proxy作为Nginx的前端代理,用来代理前端页面UI访问和镜像上传下载流量
ui:提供了一个WEB管理界面,还包含一个前端页面和后端API,底层使用mysql数据库
registry:镜像仓库,复制存储镜像文件,当镜像上传完毕后通过hook通知UI创建repository,registry的token认证通过UI组件完成
adminserver:系统配置管理中心附带检测存储用量,UI和jobserver启动时候需要加载adminserver的配置
jobserver:复制镜像复制工作,他和registry通信,从一个registry pull镜像然后push到另一个registry,并记录job_log
log:日志汇总组件,通过docker的log-driver把日志汇总到一起

harbor安装

harbor在物理机上安装时非常困难的,因此为了简化harbor的应用,harbor官方直接把harbor做成了在容器中运行的应用,而这个harbor在容器中它依赖于redis、mysql等很多存储系统,所以它需要编排起来好几个容器起来协同工作,因此vmware的harbor在使用时需要借助容器的单机编排工具docker compose,我们要使用docker compose就需要写一个编排脚本,就像dockerfile一样指令,写清容器之间的依赖关系

docker安装

1.卸载老版本docker

yum remove docker \
                  docker-common \
                  docker-selinux \
                  docker-engine

2.设置yum仓库

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3.安装docker

yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
 * extras: mirrors.aliyun.com
 * epel: fedora.cs.nctu.edu.tw
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   @docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 
 * base: mirrors.aliyun.com
Available Packages
yum install docker-ce-18.03.0.ce
systemctl daemon-docker
systemctl start docker
systemctl enable docker

4.修改/etc/docker/daemon.json来添加docker pull image时的加速文件

cat /etc/docker/daemon.json 
{
     
 "registry-mirrors": ["http://hub-mirror.c.163.com"]        
}

docker-compose安装

方法一:

yum -y install epel-release
yum install python-pip
pip install -U docker-compose
docker-compose -v
docker-compose version 1.23.1, build b02f130

方法二:

yum -y install epel-release
yum install compose
docker-comepose -v
docker-compose version 1.18.0, build 8dd22a9

harbor安装方式

**Online installer:**在线安装,安装程序从Docker hub下载Harbor的映像,因此,安装程序较小
**Offline installer:**离线安装,需下载harbor所有的图像,因此安装程序较大

harbor安装先决条件

Docker(五)镜像仓库Harbor_第2张图片

harbor安装步骤

下载harbor安装程序
1.6.2版本
离线下载:
wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.2.tgz
在线下载:
wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-online-installer-v1.6.2.tgz
解压:
tar xf harbor-offline-installer-v1.6.2.tgz -C /usr/local
配置harbor.cfg

在harbor.cfg中有两类参数
**必选参数:**需要在配置文件中设置这些参数。如果用户更新它们harbor.cfg并运行install.sh脚本以重新安装Harbor,它们将生效。
可选参数:这些参数对于更新是可选的,即用户可以将它们保留为默认值,并在启动Harbour后在Web UI上更新它们。如果它们已经启用harbor.cfg,它们只会在首次启动Harbour时生效。harbor.cfg将忽略对这些参数的后续更新。

必选参数:

  • hostname:目标主机的主机名,用于访问UI和注册表服务
  • ui_url_protocol:(http或者https,默认为http)用于访问UI和令牌/通知服务的协议,如果启用了公证,则此参数必须为https。默认情况下,这是http
  • db_password:用于db_auth的MySQL数据库的root密码
  • max_job_workers:(默认值为3)工作进程数量,用于处理上传下载镜像进程
  • customize_crt:(上或关闭,默认为上),如果此属性上,在准备脚本创建注册表的令牌生成/验证私钥和根证书
  • ssl_cert:SSL证书的路径,在协议为https时生效,为http时不生效
  • ssl_cert_key:SSL秘钥的路径,在协议为https时生效,为http时不生效
  • secretkey_path:用于加密或解密复制策略中远程注册表密码的密钥路径
  • adminral_url:自定义URL地址,默认为NA代表不定义
  • log_rotate_count:日志文件在被删除之前会被轮换log_rotate_count次
  • log_rotate_size:仅当日志文件大于log_rotate_size字节时才会轮换日志文件。如果大小后跟k,则假定大小以千字节为单位。如果使用M,则大小以兆字节为单位,如果使用G,则大小为千兆字节

可选参数:

  • 电子邮件设置::Harbor需要这些参数才能向用户发送“密码重置”电子邮件,并且仅在需要该功能时才需要。另外,请注意,在默认情况下SSL连接时没有启用-如果你的SMTP服务器需要SSL,但不支持STARTTLS,那么你应该通过设置启用SSL email_ssl = TRUE。如果电子邮件服务器使用自签名证书或不受信任证书,则设置email_insecure = true

    email_server = smtp.mydomain.com
    email_server_port = 25
    email_identity =
    email_username = [email protected]
    email_password = abc
    email_from = admin [email protected]
    email_ssl = false
    email_insecure = false

  • harbor_admin_password:管理员的初始密码。此密码仅在Harbor首次启动时生效。之后,将忽略此设置,并且应在UI中设置管理员密码。请注意,默认用户名/密码为admin / Harbor12345

  • auth_more:使用的身份验证类型。默认情况下,它是db_auth,即凭据存储在数据库中。对于LDAP身份验证,请将其设置为ldap_auth。

  • ldap_url:LDAP端点URL(例如ldaps://ldap.mydomain.com)。 仅在auth_mode设置为ldap_auth时使用

  • ladp_searchdn:具有搜索LDAP / AD服务器权限的用户的DN(例如uid=admin,ou=people,dc=mydomain,dc=com)

  • ldap_search_pwd:ldap_searchdn指定的用户密码

  • ldap_basedn:查找用户的基本DN,例如ou=people,dc=mydomain,dc=com。 仅在auth_mode设置为ldap_auth时使用

  • ldap_filter:用于查找用户的搜索过滤器,例如(objectClass=person)

  • ldap_uid:用于在LDAP搜索期间匹配用户的属性,它可以是uid,cn,email或其他属性

  • ldap_scope:搜索用户的范围,0-LDAP_SCOPE_BASE,1-LDAP_SCOPE_ONELEVEL,2-LDAP_SCOPE_SUBTREE。默认值为2。

  • self_registration : (打开或关闭。默认打开)启用/禁用用户注册他/她自己的能力。禁用时,新用户只能由管理员用户创建,只有管理员用户可以在Harbor中创建新用户。 注意:当auth_mode设置为ldap_auth时,始终禁用自注册功能,并忽略此标志。

  • token_expiration:令牌服务创建的令牌的到期时间(以分钟为单位),默认为30分钟

  • project_creation_restriction:用于控制用户有权创建项目的标志。默认情况下,每个人都可以创建一个项目,设置为“adminonly”,这样只有管理员才能创建项目

启动harbor
[root@CentOS local]# cd /usr/local/harbor/
[root@CentOS harbor]# vim harbor.cfg 
[root@CentOS harbor]# cat harbor.cfg |grep hostname
#The IP address or hostname to access admin UI and registry service.
hostname = 192.168.56.5             #我这里只调整了hostnmae为本机的IP地址
[root@CentOS harbor]# ls 
common                          docker-compose.clair.yml   docker-compose.yml  harbor.cfg            install.sh  NOTICE               prepare
docker-compose.chartmuseum.yml  docker-compose.notary.yml  ha                  harbor.v1.6.2.tar.gz  LICENSE     open_source_license
首次运行启动脚本会特别慢,因为需要把harbor.v1.6.2.tar.gz包展开,这个tar包中包含了docker-compose定义容器的所有镜像,
上面也有讲,harbor官方直接把harbor做成了在容器中运行的应用,而harbor所使用到的容器镜像就是在harbor.v1.6.2.tar.gz包中,
因此,需要展开此tar包,然后docker-compse定义的指令才能够调用此镜像
[root@CentOS harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 18.03.0
Note: docker-compose version: 1.18.0
[Step 1]: loading Harbor images ...
4de51055f30c: Loading layer [==================================================>]  133.2MB/133.2MB
e42dc4492c57: Loading layer [==================================================>]  23.38MB/23.38MB
6fd7d92da0ec: Loading layer [==================================================>]  3.072kB/3.072kB
92c622c62d9c: Loading layer [==================================================>]   2.56kB/2.56kB
eee26e869426: Loading layer [==================================================>]   2.56kB/2.56kB
0bdc2068fdfa: Loading layer [==================================================>]  2.048kB/2.048kB
1161820c2669: Loading layer [==================================================>]   22.8MB/22.8MB
1eebb5c60237: Loading layer [==================================================>]   22.8MB/22.8MB
Loaded image: goharbor/registry-photon:v2.6.2-v1.6.2
0155cb3a636c: Loading layer [==================================================>]  23.38MB/23.38MB
62f917db5fed: Loading layer [==================================================>]  12.16MB/12.16MB
2e192a070c25: Loading layer [==================================================>]   17.3MB/17.3MB
64fa72e486ec: Loading layer [==================================================>]  11.26kB/11.26kB
23afd47b0f1a: Loading layer [==================================================>]  3.072kB/3.072kB
3fa7415d357e: Loading layer [==================================================>]  29.46MB/29.46MB
Loaded image: goharbor/notary-server-photon:v0.5.1-v1.6.2
2f06068ec40a: Loading layer [==================================================>]    158MB/158MB
d6e5bcc842f3: Loading layer [==================================================>]  10.93MB/10.93MB
c272c6b03ae0: Loading layer [==================================================>]  2.048kB/2.048kB
7b0653de0007: Loading layer [==================================================>]  48.13kB/48.13kB
484f0b8e979d: Loading layer [==================================================>]  3.072kB/3.072kB
72004696fb26: Loading layer [==================================================>]  10.98MB/10.98MB
Loaded image: goharbor/clair-photon:v2.0.6-v1.6.2
c5362d9a52ab: Loading layer [==================================================>]    158MB/158MB
547ee492a9fc: Loading layer [==================================================>]  35.08MB/35.08MB
72ca312cce32: Loading layer [==================================================>]  2.048kB/2.048kB
ba7a5e9f2574: Loading layer [==================================================>]  3.072kB/3.072kB
8fabfc794eb2: Loading layer [==================================================>]  35.08MB/35.08MB
Loaded image: goharbor/chartmuseum-photon:v0.7.1-v1.6.2
a86040096f1b: Loading layer [==================================================>]  73.32MB/73.32MB
d81fe13ca34f: Loading layer [==================================================>]  3.584kB/3.584kB
a25703e967fd: Loading layer [==================================================>]  3.072kB/3.072kB
5a619498aaf0: Loading layer [==================================================>]  4.096kB/4.096kB
490efa0d32bb: Loading layer [==================================================>]  3.584kB/3.584kB
0a8ef8ce5e5e: Loading layer [==================================================>]  9.728kB/9.728kB
Loaded image: goharbor/harbor-log:v1.6.2
192ffc0c6a5f: Loading layer [==================================================>]  95.86MB/95.86MB
a0f6ec07aba5: Loading layer [==================================================>]  6.656kB/6.656kB
5cb4047d9a6f: Loading layer [==================================================>]  2.048kB/2.048kB
3c5d322a1758: Loading layer [==================================================>]   7.68kB/7.68kB
d69b5a088645: Loading layer [==================================================>]   2.56kB/2.56kB
38a2b4654f0b: Loading layer [==================================================>]   2.56kB/2.56kB
4f04d5805632: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-db:v1.6.2
b6bb4bf71953: Loading layer [==================================================>]  23.38MB/23.38MB
2c121a1131b7: Loading layer [==================================================>]  21.15MB/21.15MB
bdea637333e2: Loading layer [==================================================>]  21.15MB/21.15MB
Loaded image: goharbor/harbor-jobservice:v1.6.2
15e806b56692: Loading layer [==================================================>]  5.124MB/5.124MB
Loaded image: goharbor/nginx-photon:v1.6.2
b777c542e104: Loading layer [==================================================>]  10.95MB/10.95MB
c2ccff7df242: Loading layer [==================================================>]   17.3MB/17.3MB
e188e4d1b597: Loading layer [==================================================>]  11.26kB/11.26kB
ca7cd6746e0b: Loading layer [==================================================>]  3.072kB/3.072kB
c7d958c5de1a: Loading layer [==================================================>]  28.24MB/28.24MB
Loaded image: goharbor/notary-signer-photon:v0.5.1-v1.6.2
fbc524a787eb: Loading layer [==================================================>]    684MB/684MB
e8e8215cd36d: Loading layer [==================================================>]   7.68kB/7.68kB
d061c1c55f93: Loading layer [==================================================>]  197.6kB/197.6kB
Loaded image: goharbor/harbor-migrator:v1.6.2
77719882ce23: Loading layer [==================================================>]  23.38MB/23.38MB
1136e0b049e1: Loading layer [==================================================>]  15.58MB/15.58MB
4469c6f64c47: Loading layer [==================================================>]  15.36kB/15.36kB
91ffefa33975: Loading layer [==================================================>]  15.58MB/15.58MB
Loaded image: goharbor/harbor-adminserver:v1.6.2
0d6ec75380ac: Loading layer [==================================================>]  23.38MB/23.38MB
5ffcef8af51b: Loading layer [==================================================>]  26.88MB/26.88MB
334a9c59109a: Loading layer [==================================================>]  7.168kB/7.168kB
15b85ff320f4: Loading layer [==================================================>]  11.32MB/11.32MB
5118ce7d7887: Loading layer [==================================================>]  26.87MB/26.87MB
Loaded image: goharbor/harbor-ui:v1.6.2
4316b32f3d05: Loading layer [==================================================>]  84.34MB/84.34MB
0ba9b0933327: Loading layer [==================================================>]  3.072kB/3.072kB
65e524929f77: Loading layer [==================================================>]   59.9kB/59.9kB
8675c8d64203: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v1.6.2
[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/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/registryctl/env
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.
Creating harbor-log ... done
[Step 3]: checking existing instance of Harbor ...
Creating harbor-adminserver ... done
Creating harbor-ui ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating harbor-db ... 
Creating registry ... 
Creating harbor-adminserver ... 
Creating redis ... 
Creating harbor-ui ... 
Creating nginx ... 
Creating harbor-jobservice ... 
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.56.5. 
For more details, please visit https://github.com/goharbor/harbor .

80、443、4443都是harbor所监听使用到的端口,但harbor是基于容器在运行,为什么会监听到宿主机上的端口呢?harbor所使用到容器应该就是使用了容器的网络模式

[root@CentOS harbor]# ss -anplt 
State      Recv-Q Send-Q                                         Local Address:Port                                                        Peer Address:Port              
LISTEN     0      128                                                127.0.0.1:1514                                                                   *:*                   users:(("docker-proxy",pid=7892,fd=4))
LISTEN     0      128                                                        *:22                                                                     *:*                   users:(("sshd",pid=1063,fd=3))
LISTEN     0      100                                                127.0.0.1:25                                                                     *:*                   users:(("master",pid=1224,fd=13))
LISTEN     0      128                                                       :::80                                                                    :::*                   users:(("docker-proxy",pid=8473,fd=4))
LISTEN     0      128                                                       :::22                                                                    :::*                   users:(("sshd",pid=1063,fd=4))
LISTEN     0      100                                                      ::1:25                                                                    :::*                   users:(("master",pid=1224,fd=14))
LISTEN     0      128                                                       :::443                                                                   :::*                   users:(("docker-proxy",pid=8451,fd=4))
LISTEN     0      128                                                       :::4443                                                                  :::*                   users:(("docker-proxy",pid=8421,fd=4))
这里所有的容器一共有8个都是harbor所使用的容器,可以看到有
nginx容器,redis容器,数据库容器,log容器,UI容器,adminserver管理界面容器,jobservice镜像复制容器,registry仓库容器
[root@CentOS harbor]# docker ps
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS                   PORTS                                                              NAMES
d4a2b92dcae7        goharbor/harbor-jobservice:v1.6.2        "/harbor/start.sh"       6 minutes ago       Up 6 minutes                                                                                harbor-jobservice
5c696e01e8c7        goharbor/nginx-photon:v1.6.2             "nginx -g 'daemon of…"   6 minutes ago       Up 6 minutes (healthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp   nginx
28f2161eb111        goharbor/harbor-ui:v1.6.2                "/harbor/start.sh"       6 minutes ago       Up 6 minutes (healthy)                                                                      harbor-ui
a6ec8c306bd9        goharbor/redis-photon:v1.6.2             "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes             6379/tcp                                                           redis
2ae8a6ba5d56        goharbor/harbor-adminserver:v1.6.2       "/harbor/start.sh"       6 minutes ago       Up 6 minutes (healthy)                                                                      harbor-adminserver
2e5665c545f2        goharbor/registry-photon:v2.6.2-v1.6.2   "/entrypoint.sh /etc…"   6 minutes ago       Up 6 minutes (healthy)   5000/tcp                                                           registry
b9af56b327ac        goharbor/harbor-db:v1.6.2                "/entrypoint.sh post…"   6 minutes ago       Up 6 minutes (healthy)   5432/tcp                                                           harbor-db
35b0a659e6a2        goharbor/harbor-log:v1.6.2               "/bin/sh -c /usr/loc…"   6 minutes ago       Up 6 minutes (healthy)   127.0.0.1:1514->10514/tcp                                          harbor-log
harbor启动暂停

我们在使用/usr/local/harbor/install.sh脚本启动的时候,它也是调用的是docker-compose来进行对harbor的启动
因此,我们直接使用docker-compose命令对harbor进行启动、停止、暂停、恢复等操作
使用docker-compose执行操作的时候,必须在docker-compose.yml所在的同级目录内执行
暂停pause:

[root@CentOS /]# cd /usr/local/harbor/
[root@CentOS harbor]# docker-compose pause
Pausing harbor-log         ... done
Pausing redis              ... done
Pausing harbor-db          ... done
Pausing harbor-adminserver ... done
Pausing registry           ... done
Pausing harbor-ui          ... done
Pausing harbor-jobservice  ... done
Pausing nginx              ... done

恢复暂停unpause:

[root@CentOS harbor]# docker-compose unpause
Unpausing nginx              ... done
Unpausing harbor-jobservice  ... done
Unpausing harbor-ui          ... done
Unpausing registry           ... done
Unpausing harbor-adminserver ... done
Unpausing harbor-db          ... done
Unpausing redis              ... done
Unpausing harbor-log         ... done

停止stop:

[root@CentOS harbor]# docker-compose stop
Stopping nginx              ... done
Stopping harbor-jobservice  ... done
Stopping harbor-ui          ... done
Stopping registry           ... done
Stopping harbor-adminserver ... done
Stopping harbor-db          ... done
Stopping redis              ... done
Stopping harbor-log         ... done
[root@CentOS harbor]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

启动start:

[root@CentOS harbor]# docker-compose start
Starting log         ... done
Starting redis       ... done
Starting registry    ... done
Starting postgresql  ... done
Starting adminserver ... done
Starting ui          ... done
Starting proxy       ... done
Starting jobservice  ... done
harbor日志介绍
[root@CentOS harbor]#  ls /var/log/harbor/
adminserver.log  jobservice.log  postgresql.log  proxy.log  redis.log  registry.log  ui.log
  • adminserver.log:管理界面日志
  • jobservice.log:镜像复制日志
  • postgresql.log:数据存储日志
  • proxy.log:页面代理日志
  • redis.log:数据缓存日志
  • registry.log:仓库日志
  • ui.log:Web页面操作日志

harbor界面管理

输入IP地址,访问Web管理页面,默认账户 admin/Harbor12345

Docker(五)镜像仓库Harbor_第3张图片

harbor项目管理

创建第一个项目,点击项目-新建项目-devel是我新建成功的项目名称
右边有状态统计,事件日志是1.6.0版本以后才更新出的,1.6.0之前版本没有此栏

Docker(五)镜像仓库Harbor_第4张图片

harbor系统管理

harbor用户管理

创建用户,输入用户名,邮箱,密码,全名等信息,创建成功以后可以把此用户提升为管理员,可以重置密码,删除等操作

Docker(五)镜像仓库Harbor_第5张图片

harbor仓库管理

Docker(五)镜像仓库Harbor_第6张图片

harbor复制管理
harbor配置管理

认证模式
这里有个是否允许用户自己注册账号

Docker(五)镜像仓库Harbor_第7张图片

邮箱
如果有邮件服务器,可以把信息填上,如果邮件需要SSL加密,并且也启动了SSL功能,请把SSL钩上

Docker(五)镜像仓库Harbor_第8张图片

系统配置
项目是否允许除管理员以外的其他人创建和此页面的session时间

Docker(五)镜像仓库Harbor_第9张图片

标签

Docker(五)镜像仓库Harbor_第10张图片

harbor上传镜像

我们新建的项目就是我们的镜像仓库,点击进去查看上传格式

Docker(五)镜像仓库Harbor_第11张图片

1.添加非加密端口

#在其它docker机器上添加非https协议连接和端口
 "insecure-registries": ["192.168.56.5"]
# 192.168.56.5是harbor机器地址,如果后面需加80以外端口写为 "insecure-registries": ["192.168.56.5:443"]
[root@docker-node2 log]# cat /etc/docker/daemon.json 
{
     
 "registry-mirrors": ["http://hub-mirror.c.163.com"],        
 "insecure-registries": ["192.168.56.5"]
}

2.上传镜像

[root@docker-node2 /]# systemctl restart docker
镜像按照harbor所给的格式打标
[root@docker-node2 /]# docker tag nginx:latest 192.168.56.5/devel/nginx:V2
[root@docker-node2 /]# docker tag nginx:latest 192.168.56.5/devel/nginx:V3
[root@docker-node2 /]# docker tag nginx:latest 192.168.56.5/devel/nginx:V4
登录harbor
[root@docker-node2 /]# docker login 192.168.56.5
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
上传nginx的所有标签的镜像到harbor仓库中
[root@docker-node2 /]# docker push 192.168.56.5/devel/nginx
The push refers to repository [192.168.56.5/devel/nginx]
86df2a1b653b: Pushed 
bc5b41ec0cfa: Pushed 
237472299760: Pushed 
V1: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948
86df2a1b653b: Layer already exists 
bc5b41ec0cfa: Layer already exists 
237472299760: Layer already exists 
V2: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948
86df2a1b653b: Layer already exists 
bc5b41ec0cfa: Layer already exists 
237472299760: Layer already exists 
V3: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948
86df2a1b653b: Layer already exists 
bc5b41ec0cfa: Layer already exists 
237472299760: Layer already exists 
V4: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948
86df2a1b653b: Layer already exists 
bc5b41ec0cfa: Layer already exists 
237472299760: Layer already exists 
latest: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948

查看上传的镜像

Docker(五)镜像仓库Harbor_第12张图片

harbor下载镜像

我们先把本地的nginx:latest镜像删除

[root@docker-node2 /]# docker rmi nginx:latest
Untagged: nginx:latest
Untagged: nginx@sha256:b73f527d86e3461fd652f62cf47e7b375196063bbbd503e853af5be16597cb2e

在harbor管理页面也可看到下载方法

Docker(五)镜像仓库Harbor_第13张图片

[root@docker-node2 /]# docker pull 192.168.56.5/devel/nginx:latest
latest: Pulling from devel/nginx
Digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe
Status: Image is up to date for 192.168.56.5/devel/nginx:latest

镜像存储位置

镜像和容器都有docker-compose管理
镜像和数据默认都是存放在/data下
我们可以看docer-compose.yml文件来进行文件存储或者进行修改到我们的专用挂载上

[root@CentOS /]# cat /usr/local/harbor/docker-compose.yml | grep data
      - /data/registry:/storage:z                       #镜像存储位置
      - /data/database:/var/lib/postgresql/data:z       #数据存储位置
      - /data/config/:/etc/adminserver/config/:z        #管理页面配置保存位置
      - /data/secretkey:/etc/adminserver/key:z          #密钥保存位置
      - /data/:/data/:z
      - /data/secretkey:/etc/ui/key:z
      - /data/ca_download/:/etc/ui/ca/:z
      - /data/psc/:/etc/ui/token/:z
      - /data/job_logs:/var/log/jobs:z
      - /data/redis:/var/lib/redis
#查看所有仓库
[root@CentOS /]# ls /data/registry/docker/registry/v2/repositories/
devel
#查看devel仓库内的所有镜像
[root@CentOS /]# ls /data/registry/docker/registry/v2/repositories/devel/
nginx
#查看devel仓库内nginx镜像的所有标签
[root@CentOS /]# ls /data/registry/docker/registry/v2/repositories/devel/nginx/_manifests/tags/
latest  V1  V2  V3  V4

你可能感兴趣的:(k8s,docker,harbor,镜像仓库)