美文网首页玩转大数据
Harbor 私有镜像仓库的配置和使用

Harbor 私有镜像仓库的配置和使用

作者: AlienPaul | 来源:发表于2023-06-27 10:41 被阅读0次

安装步骤

环境信息

  • CentOS 7.4

升级Docker

Harbor要求docker的版本必须高于17。然而CentOS 7.4上的Docker版本为1.13.1,所以在CentOS7上必须先升级docker版本才能够安装。

直接安装的出错信息如下。提示需要升级Docker版本。

[root@test harbor]# ./install.sh

[Step 0]: checking if docker is installed ...

Note: docker version: 1.13.1
✖ Need to upgrade docker package to 17.06.0+.

升级Docker版本需要添加第三方Docker源,然后安装docker-ce,执行命令如下:

yum install -y yum-utils
# 安装阿里的docker源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce
# Harbor要求安装docker-compose
yum install docker-compose
systemctl start docker

安装完毕之后执行docker version,验证版本是否已更新:

[root@test harbor]# docker version
Client: Docker Engine - Community
 Version:           24.0.2
...

安装Harbor

下载harbor离线安装包。访问Harbor release:https://github.com/goharbor/harbor/releases下载最新的harbor-offline-installer-vx.x.x.tgz。解压到任意目录。

Docker hub镜像源在国内下载速度太慢,需要配置国内docker源。编辑/etc/docker/daemon.json,加入:

"registry-mirrors": [
    "https://dockerproxy.com",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com",
    "https://ccr.ccs.tencentyun.com"
  ]

然后重启docker daemon。

在安装前需要修改harbor的配置文件,指定IP端口号,数据存放目录等配置项。进入harbor安装包解压的目录,复制配置文件模板harbor.yml.tmplharbor.yml。按需修改如下内容:

hostname: harbor-ip
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 8090
# 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
data_volume: /home/inspur/harbor_data

注意:如果不使用https,需要注释/删除掉所有https的相关配置。

最后依次执行:

./prepare
./install.sh

如果安装没有问题,可以看到如下输出:

[+] Running 10/10
 ✔ Network harbor_harbor        Created                                                                                   1.6s
 ✔ Container harbor-log         Started                                                                                   0.5s
 ✔ Container registry           Started                                                                                   1.0s
 ✔ Container harbor-db          Started                                                                                   1.1s
 ✔ Container harbor-portal      Started                                                                                   1.2s
 ✔ Container registryctl        Started                                                                                   1.0s
 ✔ Container redis              Started                                                                                   0.8s
 ✔ Container harbor-core        Started                                                                                   1.2s
 ✔ Container nginx              Started                                                                                   1.6s
 ✔ Container harbor-jobservice  Started                                                                                   1.5s
✔ ----Harbor has been installed and started successfully.----

到此为止Harbor已安装完成。可以在浏览器打开http://harbor-ip:8090/使用admin用户和Harbor12345密码进入Harbor管理页面。

Docker配置Harbor源

直接使用docker login会出现如下问题:

Error response from daemon: Get https://harbor-ip:8090/v1/users/: http: server gave HTTP response to HTTPS client

这个错误说明docker期待着支持https的镜像源,然而我们配置的harbor不支持https。解决方法为将配置好的harbor镜像源添加为insecure-registries

修改/etc/docker/daemon.json,增加:

"insecure-registries":["harbor-ip:8090"]

接着重启docker daemon

systemctl restart docker daemon

然后执行:

[root@test folder]# docker login http://harbor-ip:8090/
Username: admin
Password:
Login Succeeded

能够登录成功。

push镜像

登录成功之后我们可以使用docker push命令推送镜像到harbor。

这里我们使用Harbor默认的library公开仓库。

在push镜像前,我们需要修改镜像的tag,格式为{harbor地址:ip/镜像仓库名/镜像名:版本号}。例如:

docker tag minio-opensource:latest harbor-ip:8090/library/minio-opensource:latest
docker push harbor-ip:8090/library/minio-opensource:latest

pull镜像

相对push来说,pull镜像较为简单了。按照上面设置的tag pull镜像到本地,然后修改tag为期待的tag(此步骤可选)。

docker pull harbor-ip:8090/library/minio-opensource:latest

相关文章

网友评论

    本文标题:Harbor 私有镜像仓库的配置和使用

    本文链接:https://www.haomeiwen.com/subject/hzxnydtx.html