docker私有仓库harbor部署教程

centos7搭建harbor私有仓库

软件包下载

wget http://harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz

下面开始安装部署,需事先安装docker、docker-compose

docker和docker-compose的安装教程可参照我的博客

docker安装

docker-compose部署

[root@localhost ~]# mkdir harbor
[root@localhost ~]# cd harbor/
[root@localhost harbor]# ls
harbor-offline-installer-v1.2.2.tgz
[root@localhost harbor]# tar -xf harbor-offline-installer-v1.2.2.tgz
[root@localhost harbor]# mv harbor /usr/local/

修改配置文件

[root@localhost harbor]# vim /usr/local/harbor/harbor.cfg

# 修改hostname,不要使用localhost或者127.0.0.1
hostname = 192.168.218.142

配置文件一些参数解释:

hostname:

用于访问用户界面和 register服务。它应该是目标机器的IP地址或完全限定的域名(FQDN)

例如192.168.195.128或 hub.kgc.cn。不要使用 localhost或127.0.0.1为主机名。

ui_url_protocol:

(http或https默认为http)用于访问UI和令牌/通知服务的协议。如果公证处于启用状态,则此参数必须为https

max_job_workers:镜像复制作业线程。

db_ password:用于 db_auth的 MySQL数据库root用户的密码。

customize_crt:

该属性可设置为打开或关闭,默认打开。打开此属性时,准备脚本创建私钥和根证书,用于生成/验证注册表令牌。当由外部来源提供密钥和根证书时,将此属性设置为off

ssI_cert:SSL证书的路径,仅当协议设置为https时才应用。

ssl_cert_key:SSL密钥的路径,仅当协议设置为https吋才应用。

secretkey_path:用于在复制策略中加密或解密远程 register密码的密钥路径。

以上的参数为所需参数,如果安装之后需要修改这些参数,则需要重新安装harbor

下面为可选参数,可在安装完成后在web 上进行修改;这些参数只会在第一次启动harbor时生效,如果后来被更新,则配置文件中的值会被忽略

Email:

Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。

请注意,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但不支持 STARTTLS,

那么应该通过设置启用 SSL email_ssl=TRUE。

harbor_admin_password:

管理员的初始密码,只在 Harbour第一次启动时生效。之后,此设置将被忽略,并且应Ul中设置管理员的密码。

请注意,默认的用户名/密码是 admin/ Harbor12345。

auth_mode:

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

self_registration:

启用/禁用用户注册功能。禁用时,新用户只能由 Admin用户创建,只有管理员用户可以在 Harbour中创建新用户。

注意:当 auth_mode设置为 Idap_auth时,自注册功能将始终处于禁用状态,并且该标志被忽略。

Token_expiration:由令牌服务创建的令牌的到期时间(分钟),默认为30分钟。

project_creation_restriction:

用于控制哪些用户有权创建项目的标志。默认情况下,每个人都可以创建一个项目。如果将其值设置为“ adminonly”,那么只有 admin可以创建项日。

verify_remote_cert:

打开或关闭,默认打开。此标志决定了当 Harbor与远程 register实例

通信时是否验证 SSL/TLS证书。将此属性设置为off将绕过SSL/TLS验证,这在远程实例具有自签名或不可信证书时经常使用。

安装harbor,直接运行install.sh这个脚本

[root@localhost 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.218.142.
For more details, please visit https://github.com/vmware/harbor .

查看harbor容器状态,docker-compose因为需要找到相应的配置文件,故需要进入harbor的目录下,再执行docker-compose命令

[root@localhost harbor]# cd /usr/local/harbor
[root@localhost 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

使用admin登陆harbor,密码为默认的Harbor12345

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

在浏览器访问http://192.168.218.142,即可访问harbor网页端

如图:

在这里插入图片描述

在这里插入图片描述

尝试上传镜像

在浏览器端,创建一个新的project,名为test

在这里插入图片描述

修改镜像名,格式为:harbor-ip/project-name/image

注意,如果harbor上没有对应的project,是不能上传成功 的!

[root@localhost harbor]# docker tag nginx 127.0.0.1/test/nginx:v1
[root@localhost harbor]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
127.0.0.1/test/nginx        v1                  e791337790a6        5 days ago          127MB
......

开始上传

[root@localhost harbor]# docker push 127.0.0.1/test/nginx:v1
The push refers to repository [127.0.0.1/test/nginx]
be91fceb796e: Pushed
919b6770519b: Pushing [==========================================>        ]  48.68MB/57.56MB
b60e5c3bcef2: Pushing [======================>                            ]  30.91MB/69.21MB

待最后上传完毕,到浏览器查看我们刚刚上传的镜像

在这里插入图片描述

可以看到,镜像已成功上传

下面将本地的127.0.0.1/test/nginx:v1镜像删除,再尝试从仓库中拉取镜像

[root@localhost harbor]# docker rmi 127.0.0.1/test/nginx:v1
Untagged: 127.0.0.1/test/nginx:v1
Untagged: 127.0.0.1/test/nginx@sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee

拉取

[root@localhost harbor]# docker pull 127.0.0.1/test/nginx:v1
v1: Pulling from test/nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 127.0.0.1/test/nginx:v1
127.0.0.1/test/nginx:v1
[root@localhost harbor]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
nginx                       latest              e791337790a6        5 days ago          127MB
127.0.0.1/test/nginx        v1                  e791337790a6        5 days ago          127MB

仓库的镜像已成功拉取到本地

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值