harbor的https和http配置
当私有harbor仓库搭建完成之后,在使用docker pull 或者docker push命令时可能会出现拒绝连接的情况:
$docker login registry.test.myop.com
Error response from daemon: Get https://registry.test.myop.com/v2/: dial tcp registry.test.myop.com:443: connect: connection refused
查阅相关博客之后,了解:
docker1.3.2版本开始默认docker registry使用的是https,我们设置Harbor默认http方式,所以当执行用docker login、pull、push等命令操作非https的docker regsitry的时就会报错。
解决办法:(daemon.json 的配置)
1、编辑harbor及client机器的docker配置文件
若系统是Centos7,可以在/etc/docker/daemon.json 修改。
vim /etc/docker/daemon.json
{
"insecure-registries": [
"harbor_ip or harbor_domain"
]
}
或者复制下面的当做daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
},
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 10,
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"insecure-registries":["registry.test.myop.com"],
"group":"docker"
}
2、在/etc/hosts文件中添加域名映射关系
daemon.json中配置的是域名,在hosts中添加
IP地址 域名(中间隔一个空格)
重启虚拟机生效
3、在harbor那台服务器,在harbor的安装目录
#修改harbor机器配置上docker-compose.yml的port
vim docker-compose.yml
dns_search:
ports:
- 5000:5000
4.重启或重装harbor
$docker-compose stop
#该命令是删除所有与harbor有关的容器,使用docker-compose start可能会启动不了,可以./install.sh重新安装一遍(docker-compose.yml会重置)
$docker ps -a |grep harbor |awk '{print $1}'|xargs -I {} docker rm {}
#删除Removing Harbor's database and image data
$ rm -r /data1/database
$ rm -r /data1/registry
#重启docker-compose start
docker-compose start
#reload docker
systemctl daemon-reload
#docker ps |grep -v CONTAINER |awk '{print $1}'>docker_online.txt
#cat docker_online.txt |while read line; do echo "$line"; docker start $line; done;
#systemctl start docker #服务会停止,使用reload较好。
systemctl reload docker
systemctl status docker.service -l
(注:在执行rm -r /data1/database可能会提示目录不存在,在重新启动harbor的时候会提示ERROR: No containers to start。我选择的时候使用./install.sh重新安装一遍harbor,即可启动。)
5.登录仓库
harbor机器测试登录
docker login registry.test.myop.com
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
远程机器登录 如果是远程登录的话,也会出现相同错误,处理如下。
vim /etc/docker/daemon.json
{
"insecure-registries": [
"harbor_ip or harbor_domain"
]
}
$systemctl daemon-reload
$docker ps
$systemctl reload docker
$systemctl status docker.service -l
说明: 有些文章说https登录出错,需要修改docker.service如下。不过在本测试环境 Docker version 18.06.1,harbor-1.8.4下并不需要修改docker.service 。相反,若是配置了docker.service文件的话,在docker restart之后,可能会面临启动报错的情况。
参考文章链接:https://juejin.cn/post/6844903998722424845
更多推荐
所有评论(0)