「掘金笔记」Docker推送私服Harbor

开发小伙伴难免会跟运维打交道。那么,生产微服务jar打包镜像文件,提供给运维进行k8s部署。根据遗忘曲线,你懂的。现在,做个小本本笔记。

温馨提醒: 只操作一遍最好要做笔记

我的机器:Centos 7.6_64

具体动手

所谓,动口还不如动手。不信,自己练练看看。我们开始操作吧。

步骤1 配置域名

使用root账号登录到云环境,输入vi /etc/hosts命令
由于私服是保密,防止信息泄露,所以采用域名,进行添加配置:

# 私服地址
183.xxx.xxx.189 harbor.pig4cloud.cn

步骤2 安装容器

安装,由于这个操作,导致默认安装docker 1.13.1版本,太低了

yum -y install docker

查看版本,但是需要最新版本,所以重新卸载安装。

[root@hadoop ~]# docker -v
Docker version 1.13.1, build cccb291/1.13.1

拓展如何将Docker升级到最新版本

  • 1.查包
[root@hadoop ~]# rpm -qa | grep docker
docker-client-1.13.1-109.gitcccb291.el7.centos.x86_64
docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64
docker-1.13.1-109.gitcccb291.el7.centos.x86_64
  • 2.卸载【谨慎操作】
yum remove docker-client-1.13.1-109.gitcccb291.el7.centos.x86_64
yum remove docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64
yum remove docker-1.13.1-109.gitcccb291.el7.centos.x86_64
  • 3.使用curl升级到最新版
curl -fsSL https://get.docker.com/ | sh
  • 4.重启&自启Docker
systemctl restart docker
systemctl enable docker
    1. 查看版本
[root@hadoop ~]# docker -v
Docker version 19.03.8, build afacb8b

步骤3 本机查看Harbor

如果你是win笔记本或者mac笔记本,那么需要在你环境里面进行配置host地址。强烈建议采用Switchhosts工具使用方法,然后访问:

http://harbor.pig4cloud.cn:8090/

温馨提醒:账号密码另外提供,主要防止文档传阅,导致敏感信息泄漏。任何文件都必须采用PDF格式,防篡改。

步骤4 登录私服Harbor【重点】

[root@hadoop dubbo]# docker login harbor.pig4cloud.cn
Username: pig4cloud
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

问题与解决的方法论,既然来问题,那么我们就开始排查吧,各种百度、谷歌、必应、搜狐等等搜索工具都派上用场。但是,答案终究是五花八门,各具特色。我们需要不断的验证、过滤,采坑的过程味道还是挺不好受的,踩了好几次就知道自己还是笔记一下。

  • 问题:
    http: server gave HTTP response to HTTPS client
  • 解决:
[root@hadoop pig_java]# cat /etc/docker/daemon.json
{
  "insecure-registries": [
    "http://harbor.pig4cloud.cn:8090"
  ]
}

以上配置完成以后使用命令

systemctl daemon-reload
systemctl restart docker.service
systemctl enable docker.service

正常情况

[root@hadoop docker]# docker login http://harbor.pig4cloud.cn:8090
Username: pig4cloud
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

个人教训总结,这个问题是docker版本问题导致登录不了,在追求yum -y install docker,导致版本过低。目前,还是建议按照最新版本来操作。

[root@hadoop ~]# docker -v
Docker version 19.03.8, build afacb8b
发布了89 篇原创文章 · 获赞 25 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/u010638673/article/details/105465720