Docker 之 搭建Harbor私有镜像仓库并验证成功

 

  1. 必备环境:
    CentOS 7.6 64位、docker、docker-compose、Harbor安装包
  2. docker环境上篇文章已经记录,可以参考https://blog.csdn.net/N4start/article/details/104031762
  3. 接下来安装docker-compose
    [root@VM_0_11_centos ~]# curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  4. 然后授权限 
    [root@VM_0_11_centos ~]# chmod +x /usr/local/bin/docker-compose
  5. 就可以查看到docker-compose的版本了 
    [root@VM_0_11_centos ~]# docker-compose -version
    docker-compose version 1.22.0, build f46880fe
  6.  下载安装harbor包:点击github查看下载
  7. 拷贝进文件夹,解压:
  8. [root@VM_0_11_centos /]# mkdiir /harbor
    [root@VM_0_11_centos /]# cd /harbor/
    [root@VM_0_11_centos harbor]#tar -xzvf harbor-offline-installer-v1.10.1.tgz
    

    解压完成后,进入harbor文件夹,修改配置文件:

    [root@VM_0_11_centos harbor]# cd ./harbor/
    [root@VM_0_11_centos harbor]# ls
    ca.key  common  common.sh  docker-compose.yml  harbor.v1.10.1.tar.gz  harbor.yml  install.sh  LICENSE  prepare
    [root@VM_0_11_centos harbor]# vim harbor.yml
    
    
  9. harboe.yml里面简单修改:
    #hostname为服务器本机ip
    hostname: ip


    #采用http,port为harbor的访问端口,自行定义,默认80,但因为很多时候80是常用端口,避免占用,自行修改,注释https配置

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

    # 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 为管理员登录密码,账号为admin,密码自行设置
    harbor_admin_password: password


    # Harbor DB configuration
    database:
      # The password for the root user of Harbor DB. Change this before any production use.
    #password 为数据库密码,自行设置
      password: password
      # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
      max_idle_conns: 50
      # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
      # Note: the default number of connections is 100 for postgres.
      max_open_conns: 100

  10. 修改配置完,安装

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

    等待安装即可。

  11. 打开浏览器,访问http://ip:port/(ip和port均为配置文件设置的值)
    登录密码为配置文件设置,登录后,新建一个test项目:

  12. 这时,我们需要添加私有仓库地址配置才可以在宿主机上登录harbor

    [root@VM_0_11_centos harbor]# vim /etc/docker/daemon.json
    

    把配置添加进去:
    #注意:这里的ip为服务器ip,端口为配置文件port
    {
    "registry-mirrors": ["https://zydiol88.mirror.aliyuncs.com"],
    "insecure-registries": ["ip:port"]
    }
    执行重启:

    #使配置生效
    [root@VM_0_11_centos harbor]# systemctl daemon-reload
    #重启docker
    [root@VM_0_11_centos harbor]# systemctl restart docker
    #停harbor
    [root@VM_0_11_centos harbor]# docker-compose down
    #启动harbor
    [root@VM_0_11_centos harbor]# docker-compose up -d


    此时就可以在宿主机登录harbor了,ip和端口为配置文件设置值,第一次登录需要输入账号密码:

    [root@VM_0_11_centos harbor]# docker login XXX.XXX.XX.XX:XXXX
    Authenticating with existing credentials...
    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
    

     

  13. 我们需要在docker镜像里面,找一个测试镜像进行打标签:
    #镜像列表
    [root@VM_0_11_centos harbor]# docker images
    mytomcat                              latest                           a881f3836c33        2 days ago          652MB
    tomcat                                latest                           f6ffbe316e00        2 days ago          652MB
    goharbor/chartmuseum-photon           v0.9.0-v1.10.1                   0245d66323de        4 months ago        128MB
    goharbor/harbor-migrator              v1.10.1                          a4f99495e0b0        4 months ago        364MB
    goharbor/redis-photon                 v1.10.1                          550a58b0a311        4 months ago        111MB
    goharbor/clair-adapter-photon         v1.0.1-v1.10.1                   2ec99537693f        4 months ago        61.6MB
    goharbor/clair-photon                 v2.1.1-v1.10.1                   622624e16994        4 months ago        171MB
    goharbor/notary-server-photon         v0.6.1-v1.10.1                   e4ff6d1f71f9        4 months ago        143MB
    goharbor/notary-signer-photon         v0.6.1-v1.10.1                   d3aae2fc17c6        4 months ago        140MB
    goharbor/harbor-registryctl           v1.10.1                          ddef86de6480        4 months ago        104MB
    goharbor/registry-photon              v2.7.1-patch-2819-2553-v1.10.1   1a0c5f22cfa7        4 months ago        86.5MB
    goharbor/nginx-photon                 v1.10.1                          01276d086ad6        4 months ago        44MB
    goharbor/harbor-log                   v1.10.1                          1f5c9ea164bf        4 months ago        82.3MB
    goharbor/harbor-jobservice            v1.10.1                          689368d30108        4 months ago        143MB
    goharbor/harbor-core                  v1.10.1                          14151d58ac3f        4 months ago        130MB
    goharbor/harbor-portal                v1.10.1                          8a9856c37798        4 months ago        52.1MB
    goharbor/harbor-db                    v1.10.1                          18548720d8ad        4 months ago        148MB
    goharbor/prepare                      v1.10.1                          897a4d535ced        4 months ago        192MB
    
    #打tag,例如:docker tag 镜像名:标签 私服地址/仓库项目名/镜像名:标签
    [root@VM_0_11_centos harbor]# docker tag mytomcat:latest ip:port/test/tomcat-test:v1.0
    

    推送镜像到私有仓库:

    # 推送 ,例如:docker push  私有仓库地址/仓库项目名/镜像名:标签 
    [root@VM_0_11_centos harbor]# docker push ip:port/test/tomcat-test:v1.0
    
  14. 等到推送成功,再次进去harbor的ui界面,即可看到推送的镜像:
    至此,harbor搭建完成!

猜你喜欢

转载自blog.csdn.net/N4start/article/details/106871703