安装docker私有仓库harbor以及使用

  • 安装harbor
  • 使用harbor
  • 新建项目
  • 创建用户,分配权限
  • Docker 镜像复制




harbor官方文档

主机

IP

docker

192.168.30.150/24

安装harbor


1.安装docker-compose

[root@docker ~]# yum -y install docker-compose



2.将压缩包解压
其他版本的下载地址

[root@docker ~]# cd /usr/src/
[root@docker ~]# wget https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz


[root@docker src]# tar xf harbor-offline-installer-v2.0.2.tgz -C /usr/local

[root@docker src]# cd /usr/local/harbor

[root@docker harbor]# ls
common.sh  harbor.v2.0.2.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare



3.复制一份harbor.yml

[root@docker harbor]# cp harbor.yml.tmpl harbor.yml



4.修改配置文件

/改为自己IP
hostname: 192.168.30.150


http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80


/没有证书,就把https注释掉
# https related config
#https:
  # https port for harbor, default is 443
#  port: 443
  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path



harbor_admin_password: Harbor12345



启动

[root@docker harbor]# ./install.sh 
✔ ----Harbor has been installed and started successfully.----


[root@docker harbor]# ss -anlt
State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN     0      128                     *:22                                  *:*                  
LISTEN     0      100             127.0.0.1:25                                  *:*                  
LISTEN     0      128             127.0.0.1:1514                                *:*                  
LISTEN     0      128                    :::80                                 :::*                  
LISTEN     0      128                    :::22                                 :::*                  
LISTEN     0      100                   ::1:25                                 :::*


使用harbor

登录

Dockerfile使用Harbor镜像 docker harbor使用方法_json



Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_02


我们可以看到系统各个模块如下:


项目:新增/删除项目,查看镜像仓库,给项目添加成员、查看操作日志、复制项目等

日志:仓库各个镜像create、push、pull等操作日志


系统管理

  • 用户管理:新增/删除用户、设置管理员等
  • 仓库管理:新增/删除从库目标、新建/删除/启停复制规则等
  • 复制管理:认证模式、复制、邮箱设置、系统设置等
  • 标签
  • 全局级别标签:由系统管理员管理,用于管理整个系统的镜像。它们可以添加到任何项目下的镜像中。
  • 项目级别标签:由项目管理员或者系统管理员在项目下管理,只能添加到本项目的镜像中。
  • 项目定额:分配每个项目多少存储空间
  • 审查服务:扫描漏铜
  • 垃圾清理:清理不需要的镜像
  • 配置管理:认证设置、邮箱设置、系统设置

注意:非系统管理员用户登录,只能看到有权限的项目和日志,其他模块不可见。



新建项目

当项目公开时,任何人都有此项目下镜像的读权限。命令行用户不要"docker login"就可以拉去此项目下的镜像

Dockerfile使用Harbor镜像 docker harbor使用方法_json_03



Dockerfile使用Harbor镜像 docker harbor使用方法_json_04




新建项目完后,就可以登录传镜像了

但会出现一个问题

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

出现这问题的原因是:Docker自从1.3.X之后docker registry交互默认使用的是HTTPS,但是搭建私有镜像默认使用的是HTTP服务,所以与私有镜像交时出现以上错误。
因此我们需要在/etc/docker/daemon.json加上 “insecure-registries”:[“harborIP”]

[root@docker harbor]# vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://qtfb3ml8.mirror.aliyuncs.com"],
  "insecure-registries":["192.168.30.150"]
}

//重启服务
[root@docker harbor]# systemctl restart docker


再次登录

[root@docker ~]# docker login 192.168.30.150
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@docker ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              4bb46517cac3        2 weeks ago         133MB

//改标签
[root@docker ~]# docker tag nginx:latest 192.168.30.150/nginx/nginx:v0.1


[root@docker ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
192.168.30.150/nginx/nginx      v0.1                4bb46517cac3        2 weeks ago         133MB
nginx                           latest              4bb46517cac3        2 weeks ago         133MB


Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_05



Dockerfile使用Harbor镜像 docker harbor使用方法_json_06




创建用户,分配权限

创建用户

Dockerfile使用Harbor镜像 docker harbor使用方法_json_07



Dockerfile使用Harbor镜像 docker harbor使用方法_docker_08




添加到nginx项目中,并设置权限

Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_09



Dockerfile使用Harbor镜像 docker harbor使用方法_docker_10



Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_11




同样的,harbor我们是使用的http,因此这里也需要添加

[root@user ~]# vim /etc/docker/daemon.json 
{
  "insecure-registries":["192.168.30.150"],
  "registry-mirrors": ["https://qtfb3ml8.mirror.aliyuncs.com"]
}

[root@user ~]# systemctl restart docker


登录

[root@user ~]# docker login 192.168.30.150
Username: zyy
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@user ~]# docker tag nginx:latest 192.168.30.150/nginx/nginx:v0.2
[root@user ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
nginx                        latest              4bb46517cac3        2 weeks ago         133MB
192.168.30.150/nginx/nginx   v0.2                4bb46517cac3        2 weeks ago         133MB

[root@user ~]# docker push 192.168.30.150/nginx/nginx:v0.2
The push refers to repository [192.168.30.150/nginx/nginx]
550333325e31: Layer already exists 
22ea89b1a816: Layer already exists 
a4d893caa5c9: Layer already exists 
0338db614b95: Layer already exists 
d0f104dc0a1f: Layer already exists 
v0.2: digest: sha256:179412c42fe3336e7cdc253ad4a2e03d32f50e3037a860cf5edbeb1aaddb915c size: 1362


查看镜像

Dockerfile使用Harbor镜像 docker harbor使用方法_json_12






Docker 镜像复制

harbor

IP

harbor001

192.168.30.150/24

harbor002

192.168.30.244/24



在仓库管理,新建一个目标

Dockerfile使用Harbor镜像 docker harbor使用方法_json_13



RUL为对端IP

Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_14



Dockerfile使用Harbor镜像 docker harbor使用方法_json_15




在复制管理,添加规则

Dockerfile使用Harbor镜像 docker harbor使用方法_nginx_16



Dockerfile使用Harbor镜像 docker harbor使用方法_json_17



因为是手动,所以点一下复制,就可以同步了

Dockerfile使用Harbor镜像 docker harbor使用方法_docker_18



在192.168.30.244上查看,同步完成

Dockerfile使用Harbor镜像 docker harbor使用方法_docker_19



Dockerfile使用Harbor镜像 docker harbor使用方法_json_20