• 企业DevOps之路:发布镜像到 Harbor 仓库


    1. Harbor 服务绑定 host

    [root@localhost harbor]# vi /etc/hosts
    [root@localhost harbor]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.10.8 harbor.olive.org

    2. 登录 Harbor 镜像仓库

    [root@localhost harbor]# docker login harbor.olive.org
    Username: admin
    Password:
    Error response from daemon: Get "https://harbor.olive.org/v2/": dial tcp 192.168.10.8:443: connect: connection refused

    出现以上拒绝连接的错误,是因为在使用 docker 的仓库时,Registry为了安全性考虑,默认是需要 https 证书支持。除了生成证书,配置https的办法之外;在实验环境中,还可以通过修改 docker 的配置文件 daemon.json 把Harbor地址加入到Docker信任列表来解决。

    /etc/docker/daemon.json 是 docker 的配置文件,默认是没有的,需要手动创建,可进行如下配置:

    vi /etc/docker/daemon.json

    添加 insecure-registries 字段,在列表里加入自己的 ip 或者域名

    {
      "insecure-registries": ["http://harbor.olive.org"]
    }

    修改后重启 docker

    #重新获取配置
    systemctl daemon-reload
    #重新启动docker
    systemctl restart docker

    重启 docker 之后,可能会遇到 Harbo r无法正常访问的情况;这是因为 docker重启后,Harbor 相关的容器没有自动启动,只要将所有的 Harbor 容器重启即可,最好先启动 harbor-log 这个容器。

    可以使用命令 docker restart containerID逐个重启,也可以使用 docker-compose 进行重新启动:

    [root@localhost harbor]# cd /usr/local/harbor
    [root@localhost harbor]# docker-compose stop
    [root@localhost harbor]# docker-compose up -d

    这个 Harbor 启动和停止操作必须在 Harbor 的安装目录下操作以上命令,否则会报找不到docker-compose.yml的错误。

    再次登录 Harbor

    [root@localhost harbor]# docker login harbor.olive.org
    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@localhost harbor]#

    3. 推送镜像到 Harbor 仓库

    • 镜像打标签

    docker tag centos-jre8:v1.0 harbor.olive.org/omg/centos-jre8:v1.0

    centos-jre8:v1.0是由下图的 REPOSITORY+TAG 组成;使用docker images命令查看

    • 在 Harbor 创建项目

    • 推送镜像

    docker push harbor.olive.org/omg/centos-jre8:v1.0

    没在 Harbor 创建项目,就进行镜像推送;出现以下错误:报找不到omg项目

    [root@localhost harbor]# docker push harbor.olive.org/omg/centos-jre8:v1.0
    The push refers to repository [harbor.olive.org/omg/centos-jre8]
    6575c18211a0: Preparing
    15836fdef74a: Preparing
    174f56854903: Preparing
    unauthorized: project omg not found: project omg not found

    创建项目后,推送

    [root@localhost harbor]# docker push harbor.olive.org/omg/centos-jre8:v1.0
    The push refers to repository [harbor.olive.org/omg/centos-jre8]
    6575c18211a0: Pushed
    15836fdef74a: Pushed
    174f56854903: Pushed
    v1.0: digest: sha256:3cba5aaf993441fb237ab950b2d207ee624a801dd031ecb35e8f72ef03e99cb4 size: 948

    4. 从 Harbor 仓库拉取镜像

    • 先登录

    docker login -u admin -p Harbor123 harbor.olive.org
    • 拉取镜像

    docker pull harbor.olive.org/omg/centos-jre8:v1.0

    另外拉取镜像的地址也可以在如下 Harbor 界面找到

    这里复制出来的是ip,如果使用这个拉取命令,需要修改一下/etc/docker/daemon.jsoninsecure-registries字段增加 ip。

    docker pull 192.168.10.8/omg/centos-jre8@sha256:3cba5aaf993441fb237ab950b2d207ee624a801dd031ecb35e8f72ef03e99cb4

    5.  登出 Harbor 镜像仓库

    [root@localhost harbor]# docker logout harbor.olive.org
    Removing login credentials for harbor.olive.org
  • 相关阅读:
    c# TCP高性能通信
    c#实现的HTTP服务端
    c#的二进制序列化组件MessagePack介绍
    c# 任务超时执行
    c#项目总结
    etcd客户端c#
    开发的服务集群部署方案,以etcd为基础(java)
    udt的java版本judt项目持续升级1.2版本
    udt通信java再次升级1.1版
    (转)Spring Boot(二) & lombok
  • 原文地址:https://www.cnblogs.com/happyhuangjinjin/p/16129497.html
Copyright © 2020-2023  润新知