前言
在离线手动部署 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 这样的浏览器, 最好使用谷歌浏览器
来源: http://blog.51cto.com/10950710/2301257