前言

离线手动部署docker镜像仓库——harbor仓库(一) 离线手动部署docker镜像仓库——harbor仓库(二)的实验中,遇到一些harbor仓库部署的问题,在此做个小结。 实验环境: harbor服务器系统:CentOS Linux release 7.4.1708 (Core) harbor服务器IP:10.0.0.101(test101) harbor版本:v1.5.0 docker版本:1.13.1 使用了另一台机器做pull和push镜像测试:10.0.0.102(test102)

问题集锦

1、docker配置文件没生效,引起的push镜像失败,报错10.0.0.101:443: getsockopt: connection refused

问题描述:

在test101机器刚刚部署好harbor的时候,push镜像失败了,报“Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused”

[root@test101 nginx]# docker push 10.0.0.101/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101/test/bigdatacenter]
Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused
[root@test101 nginx]# 

原因分析:

是因为配置文件里面配置的--insecure-registry=10.0.0.101这一行配置没有生效(修改了配置之后,有重启docker,但是这行内容也没有加载成功):

解决方法:

再次重新启动了docker服务,使之重新加载配置文件

[root@test101 harbor]# systemctl daemon-reload     #重启docker之前,先执行了这个步骤,很重要
[root@test101harbor]# systemctl restart docker

然后测试登录harbor仓库,就OK了:

[root@test101 harbor]# docker login 10.0.0.101
Username: admin
Password: 
Login Succeeded

再push镜像就成功了:

[root@test101 harbor]# docker push 10.0.0.101/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101/test/bigdatacenter]
df9d7f53cb5b: Pushed 
ab0926f7eb13: Pushed 
24a30430d761: Pushed 
20dd87a4c2ab: Layer already exists 
78075328e0da: Layer already exists 
9f8566ee5135: Layer already exists 
latest: digest: sha256:07c467b4f8c6cfa306484bd060721fb621ddb1fd43f528ef5a0df1157d8bd853 size: 1573
[root@test101 harbor]#

2、端口问题引起的pull镜像报错Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused

问题描述:

把harbor端口默认的80端口修改为1180,然后打了个测试镜像上去,但是在test102机器pull镜像的时候失败了,报错如下:

[root@test102 ~]# docker pull 10.0.0.101/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101/test/bigdatacenter ... 
Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused

解决办法:

1)想起来test102机器上的docker的配置文件没有修改,于是在 /etc/sysconfig/docker 加上了“--insecure-registry=10.0.0.101:1180”: 然后重启了docker服务:

[root@test102 ~]# systemctl restart docker
[root@test102 ~]# 

再重新pull镜像,发现报错不一样了:

[root@test102 ~]# docker pull 10.0.0.101/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101/test/bigdatacenter ... 
Pulling repository 10.0.0.101/test/bigdatacenter
Error while pulling image: Get http://10.0.0.101/v1/repositories/test/bigdatacenter/images: dial tcp 10.0.0.101:80: getsockopt: connection refused

2)报错dial tcp 10.0.0.101:80: getsockopt: connection refused,是因为镜像名称里面没有加上1180端口,就默认去80端口找镜像了,于是在命令里面加上了1180端口:

[root@test102 ~]# docker pull 10.0.0.101:1180/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101:1180/test/bigdatacenter ... 
Get https://10.0.0.101:1180/v1/_ping: http: server gave HTTP response to HTTPS client   #关于这个报错,网上有很多文章说是关于docker和harbor之间的交互存在一个http和https之间的问题,建议改/etc/docker/daemon.json 。但是按照网上的方法试了,改了/etc/docker/daemon.json 之后,docker服务起不来,没法解决。最后还是尝试使用systemctl daemon-reload+systemctl restart docker两条命令解决了问题
[root@test102 ~]# 

3)加上1180端口之后,报错不一样了,于是试着像上一个问题一样,尝试执行systemctl daemon-reload命令。重新载入 systemd,扫描新的或有变动的单元,然后再重启docker:

[root@test102 ~]# systemctl daemon-reload
[root@test102 ~]# systemctl restart docker

再pull镜像,发现就成功了!

[root@test102 ~]# docker pull 10.0.0.101:1180/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101:1180/test/bigdatacenter ... 
latest: Pulling from 10.0.0.101:1180/test/bigdatacenter
53478ce18e19: Pull complete 
d1c225ed7c34: Pull complete 
c6724ba0c09a: Pull complete 
de3b8705ee9f: Pull complete 
c091a284f068: Pull complete 
010503dbdd2d: Pull complete 
Digest: sha256:ce823873379c519a583756783923dd160473a60fcf78dfd869e8b33f5198f237
Status: Downloaded newer image for 10.0.0.101:1180/test/bigdatacenter:latest
[root@test102 ~]# 

注意,问题1和2说明,修改了docker的配置文件 /etc/sysconfig/docker之后,重启docker服务,文件不一定生效了,如果发现没生效,别忘了“systemctl daemon-reload”这条命令!

3、push镜像失败,报denied: requested access to the resource is denied

问题描述:

部署好harbor仓库的时候,push镜像失败了,报denied: requested access to the resource is denied

[root@test101 harbor]# docker push 10.0.0.101:1180/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101:1180/test/bigdatacenter]
d7393e4babfa: Preparing 
d8db36d925b6: Preparing 
93fc2863a9fb: Preparing 
20dd87a4c2ab: Preparing 
78075328e0da: Preparing 
9f8566ee5135: Waiting 
denied: requested access to the resource is denied

解决办法:

遇到这种情况,登录一下harbor仓库,登录成功,就OK了。 关于原因和解决方法,在网上查了,说法不一,也有很多其他的方法,但是没有试过,就试着登录了一下,然后问题就解决了,部署过程中遇到好几次这个问题,都是这样解决的。当换了用户名/密码/端口/域名什么的,在push镜像的时候就可能会出现这个问题。

[root@test101 harbor]# docker login 10.0.0.101:1180      #登录一下就好了
Username: admin
Password: 
Login Succeeded

然后再重新push镜像,就成功了

[root@test101 harbor]# docker push 10.0.0.101:1180/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101:1180/test/bigdatacenter]
d7393e4babfa: Pushed 
d8db36d925b6: Pushed 
93fc2863a9fb: Pushed 
20dd87a4c2ab: Pushed 
78075328e0da: Pushed 
9f8566ee5135: Pushed 
latest: digest: sha256:63a86f231cf0415fe02ac11e31b00a959563ff3e264955c7c0236bd398b1c775 size: 1573
[root@test101 harbor]# 

4、360浏览器设置问题引起的harbor仓库访问异常

问题描述:

部署好harbor仓库之后,发现浏览器访问界面出不来,一直处于这样的状态:

原因分析:

后来发现因为这台机器上只有360浏览器,存在模式的区别,现在用的是默认的兼容模式,所以界面出不来,并非服务的问题。

解决办法:

把浏览器换成极速模式就好了: 为了避免这种不必要的问题,最好不要用360这样的浏览器,最好使用Chrome浏览器

5、harbor项目访问级别引起pull镜像失败

问题描述:

测试在rancher2.0上部署一个harbor仓库的服务到服务器上,发现拉取镜像失败,报错repository does not exist or may require ‘docker login’:

原因分析:

因为harbor仓库的项目访问级别设置成了私有,所以rancher-server和agent服务器都访问不到,因此报错无法拉取镜像。 因为在服务器上测试手动pull镜像,是测试的公开项目里面的镜像,所以没有发现该问题:

解决方法:

将harbor上面项目的访问级别设置为公开,就好了

6、错误配置harbor地址,导致pull镜像失败

问题描述:

在另一次使用rancher2.0测试部署服务的时候,服务器上拉取了harbor仓库的web镜像,但是拉取镜像一直失败,报错如下:

原因分析:

看到这个熟悉的错误信息,马上查看docker配置文件,发现harbor的地址多写了个http://

解决方法:

去掉配置文件的http:// 然后重启docker服务即可:

然后重启docker服务,重新部署,恢复正常:

7、curl安装docker-compose失败:

问题描述:

安装docker-compose报错如下:

[root@test101 home]# sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) Peer reports incompatible or unsupported protocol version.
[root@test101 home]# 

原因分析:

curl 不兼容或不支持的协议版本

解决方法:

更新curl相关组件版本:

# yum update -y nss curl libcurl

image.png