centos7搭建本地harbor仓库

一、Harbor介绍

    Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能

二、环境准备 (1台centos7的虚拟机)

        Harbor的所有服务组件都是在Docker中部署的,所以官方安装使用Docker-compose快速部署,所以需要安装Docker、Docker-compose。由于Harbor是基于Docker Registry V2版本,所以就要求Docker-ce版本不小于17.06.0,Docker-compose版本大于等于1.6.0

        1、安装docker-ce 及基础环境

 1:yum install -y yum-utils device-mapper-persistent-data lvm2
 2:yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 3: yum list docker-ce.x86_64  --showduplicates |sort -r
 4: yum install docker-ce-17.09.1.ce -y 

       

        2、安装docker-compose        

1、curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
或者
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.3.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

2、 chmod +x /usr/local/bin/docker-compose

3、 docker-compose --version

4、 docker-compose up

                              

三、安装harbor (下载较慢)

        1、下载harbor离线安装包

1、wget https://github.com/goharbor/harbor/releases/download/v2.4.2/harbor-offline-installer-v2.4.2.tgz

2、tar -zxvf harbor-offline-installer-v2.4.2.tgz #解压离线安装包

        2、配置harbor

1、cd harbor
2、cp harbor.yml.tmpl harbor.yml
3、vim harbor.yml
   修改内容:hostname = 10.130.77.28 		#修改harbor的启动ip为你虚拟机的ip
            harbor_admin_password = admin@123 #修改harbor的admin用户的密码

         3、启动harbor  

 bash install.sh

         4、docker-compose ps 查看

 四、访问harbor(我这里是http://192.168.68.137/)   

1、新建个项目目录

  2、命令行登陆harbor ( )

 注意:第一次登录一般都会报错 

Error response from daemon: Get "https://192.168.68.137/v2/": dial tcp 10.130.77.48:443: connect: no route to host
[root@node-3 ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.68.137
修改配置文件,ExecStart之后添加 


重启docker 
    systemctl daemon-reload
    systemctl restart docker

 3、测试上传镜像到harbor

        

root@host_137 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
3f4ca61aafcd: Pull complete
50c68654b16f: Pull complete
3ed295c083ec: Pull complete
40b838968eea: Pull complete
88d3ab68332d: Pull complete
5f63362a3fa3: Pull complete
Digest: sha256:0047b729188a15da49380d9506d65959cce6d40291ccfb4e039f5dc7efd33286
Status: Downloaded newer image for nginx:latest
[root@host_137 ~]# docker docker tag nginx:latest 192.168.68.137/harbor/nginx:latest
docker: 'docker' is not a docker command.
See 'docker --help'
[root@host_137 ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              1403e55ab369        5 days ago          142MB
goharbor/harbor-exporter        v2.7.0              69796d5ea472        11 days ago         96.5MB
goharbor/chartmuseum-photon     v2.7.0              3a1128c43ada        11 days ago         227MB
goharbor/redis-photon           v2.7.0              cc91f43eb370        11 days ago         154MB
goharbor/trivy-adapter-photon   v2.7.0              acf7683e6266        11 days ago         431MB
goharbor/notary-server-photon   v2.7.0              cc32c079c5e8        11 days ago         113MB
goharbor/notary-signer-photon   v2.7.0              1c7e9e9a0c92        11 days ago         110MB
goharbor/harbor-registryctl     v2.7.0              6573a396157f        11 days ago         139MB
goharbor/registry-photon        v2.7.0              4d015df21516        11 days ago         78.1MB
goharbor/nginx-photon           v2.7.0              5f2878db2a82        11 days ago         154MB
goharbor/harbor-log             v2.7.0              6b4a9a2855bb        11 days ago         161MB
goharbor/harbor-jobservice      v2.7.0              cdde5030ac74        11 days ago         252MB
goharbor/harbor-core            v2.7.0              f1aaf647100d        11 days ago         215MB
goharbor/harbor-portal          v2.7.0              ea51148e87b6        11 days ago         162MB
goharbor/harbor-db              v2.7.0              fff87d4d50e4        11 days ago         195MB
goharbor/prepare                v2.7.0              f0f57240ce77        11 days ago         164MB
[root@host_137 ~]# docker tag nginx:latest 192.168.68.137/harbor/nginx:latest
[root@host_137 ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
192.168.68.137/harbor/nginx     latest              1403e55ab369        5 days ago          142MB
nginx                           latest              1403e55ab369        5 days ago          142MB
goharbor/harbor-exporter        v2.7.0              69796d5ea472        11 days ago         96.5MB
goharbor/chartmuseum-photon     v2.7.0              3a1128c43ada        11 days ago         227MB
goharbor/redis-photon           v2.7.0              cc91f43eb370        11 days ago         154MB
goharbor/trivy-adapter-photon   v2.7.0              acf7683e6266        11 days ago         431MB
goharbor/notary-server-photon   v2.7.0              cc32c079c5e8        11 days ago         113MB
goharbor/notary-signer-photon   v2.7.0              1c7e9e9a0c92        11 days ago         110MB
goharbor/harbor-registryctl     v2.7.0              6573a396157f        11 days ago         139MB
goharbor/registry-photon        v2.7.0              4d015df21516        11 days ago         78.1MB
goharbor/nginx-photon           v2.7.0              5f2878db2a82        11 days ago         154MB
goharbor/harbor-log             v2.7.0              6b4a9a2855bb        11 days ago         161MB
goharbor/harbor-jobservice      v2.7.0              cdde5030ac74        11 days ago         252MB
goharbor/harbor-core            v2.7.0              f1aaf647100d        11 days ago         215MB
goharbor/harbor-portal          v2.7.0              ea51148e87b6        11 days ago         162MB
goharbor/harbor-db              v2.7.0              fff87d4d50e4        11 days ago         195MB
goharbor/prepare                v2.7.0              f0f57240ce77        11 days ago         164MB
[root@host_137 ~]# docker push 192.168.68.137/harbor/nginx
The push refers to a repository [192.168.68.137/harbor/nginx]
c72d75f45e5b: Layer already exists
9a0ef04f57f5: Layer already exists
d13aea24d2cb: Layer already exists
2b3eec357807: Layer already exists
2dadbc36c170: Layer already exists
8a70d251b653: Layer already exists
latest: digest: sha256:9a821cadb1b13cb782ec66445325045b2213459008a41c72d8d87cde94b33c8c size: 1570
[root@host_137 ~]#

查看镜像仓库 

测试拉取镜像 (先将本地的镜像删除)

[root@host_137 ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              1403e55ab369        5 days ago          142MB
192.168.68.137/harbor/nginx     latest              1403e55ab369        5 days ago          142MB
goharbor/harbor-exporter        v2.7.0              69796d5ea472        11 days ago         96.5MB
goharbor/chartmuseum-photon     v2.7.0              3a1128c43ada        11 days ago         227MB
goharbor/redis-photon           v2.7.0              cc91f43eb370        11 days ago         154MB
goharbor/trivy-adapter-photon   v2.7.0              acf7683e6266        11 days ago         431MB
goharbor/notary-server-photon   v2.7.0              cc32c079c5e8        11 days ago         113MB
goharbor/notary-signer-photon   v2.7.0              1c7e9e9a0c92        11 days ago         110MB
goharbor/harbor-registryctl     v2.7.0              6573a396157f        11 days ago         139MB
goharbor/registry-photon        v2.7.0              4d015df21516        11 days ago         78.1MB
goharbor/nginx-photon           v2.7.0              5f2878db2a82        11 days ago         154MB
goharbor/harbor-log             v2.7.0              6b4a9a2855bb        11 days ago         161MB
goharbor/harbor-jobservice      v2.7.0              cdde5030ac74        11 days ago         252MB
goharbor/harbor-core            v2.7.0              f1aaf647100d        11 days ago         215MB
goharbor/harbor-portal          v2.7.0              ea51148e87b6        11 days ago         162MB
goharbor/harbor-db              v2.7.0              fff87d4d50e4        11 days ago         195MB
goharbor/prepare                v2.7.0              f0f57240ce77        11 days ago         164MB
[root@host_137 ~]# docker rmi 192.168.68.137/harbor/nginx
Untagged: 192.168.68.137/harbor/nginx:latest
Untagged: 192.168.68.137/harbor/nginx@sha256:9a821cadb1b13cb782ec66445325045b2213459008a41c72d8d87cde94b33c8c
[root@host_137 ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              1403e55ab369        5 days ago          142MB
goharbor/harbor-exporter        v2.7.0              69796d5ea472        11 days ago         96.5MB
goharbor/chartmuseum-photon     v2.7.0              3a1128c43ada        11 days ago         227MB
goharbor/redis-photon           v2.7.0              cc91f43eb370        11 days ago         154MB
goharbor/trivy-adapter-photon   v2.7.0              acf7683e6266        11 days ago         431MB
goharbor/notary-server-photon   v2.7.0              cc32c079c5e8        11 days ago         113MB
goharbor/notary-signer-photon   v2.7.0              1c7e9e9a0c92        11 days ago         110MB
goharbor/harbor-registryctl     v2.7.0              6573a396157f        11 days ago         139MB
goharbor/registry-photon        v2.7.0              4d015df21516        11 days ago         78.1MB
goharbor/nginx-photon           v2.7.0              5f2878db2a82        11 days ago         154MB
goharbor/harbor-log             v2.7.0              6b4a9a2855bb        11 days ago         161MB
goharbor/harbor-jobservice      v2.7.0              cdde5030ac74        11 days ago         252MB
goharbor/harbor-core            v2.7.0              f1aaf647100d        11 days ago         215MB
goharbor/harbor-portal          v2.7.0              ea51148e87b6        11 days ago         162MB
goharbor/harbor-db              v2.7.0              fff87d4d50e4        11 days ago         195MB
goharbor/prepare                v2.7.0              f0f57240ce77        11 days ago         164MB
[root@host_137 ~]# docker pull 192.168.68.137/harbor/nginx
Using default tag: latest
latest: Pulling from harbor/nginx
Digest: sha256:9a821cadb1b13cb782ec66445325045b2213459008a41c72d8d87cde94b33c8c
Status: Downloaded newer image for 192.168.68.137/harbor/nginx:latest
[root@host_137 ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              1403e55ab369        5 days ago          142MB
192.168.68.137/harbor/nginx     latest              1403e55ab369        5 days ago          142MB
goharbor/harbor-exporter        v2.7.0              69796d5ea472        11 days ago         96.5MB
goharbor/chartmuseum-photon     v2.7.0              3a1128c43ada        11 days ago         227MB
goharbor/redis-photon           v2.7.0              cc91f43eb370        11 days ago         154MB
goharbor/trivy-adapter-photon   v2.7.0              acf7683e6266        11 days ago         431MB
goharbor/notary-server-photon   v2.7.0              cc32c079c5e8        11 days ago         113MB
goharbor/notary-signer-photon   v2.7.0              1c7e9e9a0c92        11 days ago         110MB
goharbor/harbor-registryctl     v2.7.0              6573a396157f        11 days ago         139MB
goharbor/registry-photon        v2.7.0              4d015df21516        11 days ago         78.1MB
goharbor/nginx-photon           v2.7.0              5f2878db2a82        11 days ago         154MB
goharbor/harbor-log             v2.7.0              6b4a9a2855bb        11 days ago         161MB
goharbor/harbor-jobservice      v2.7.0              cdde5030ac74        11 days ago         252MB
goharbor/harbor-core            v2.7.0              f1aaf647100d        11 days ago         215MB
goharbor/harbor-portal          v2.7.0              ea51148e87b6        11 days ago         162MB
goharbor/harbor-db              v2.7.0              fff87d4d50e4        11 days ago         195MB
goharbor/prepare                v2.7.0              f0f57240ce77        11 days ago         164MB
[root@host_137 ~]#

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值