docker 配置harbor 非https访问(http server give HTTP response to HTTPS client)

问题

  • 本地部署了harbor镜像服务器
  • docker和docker-compose 获取该harbor镜像服务器上的镜像时报错

报错信息 http server give HTTP response to HTTPS client

报错信息说得很明白,就是docker期望访问一个https服务器,但是服务器是HTTP的。

  • 尝试命令行登录也报同样的错误

docker login -u admin harbor:31120

解决方案

方案1

网上好多教程也都有解决方案。

修改daemon.json 配置文件

bash 复制代码
vim /etc/docker/daemon.json

增加配置

js 复制代码
{ 
// ... 
"insecure-registries" : ["harbor:31120"] 
// ... 
}

重启docker 服务

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

然后发现不起作用。

使用docker info 命令,看不到刚才的配置harbor信息

解决方法2

配置systemd服务启动文件

bash 复制代码
[0 root@vps harbor]# cat /usr/lib/systemd/system/docker.service

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service containerd.service

Wants=network-online.target

Requires=docker.socket containerd.service

[Service]

Type=notify

# the default is not to use systemd for cgroups because the delegate issues still

# exists and systemd currently does not support the cgroup feature set required

# for containers run by docker

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry harbor:31120

ExecReload=/bin/kill -s HUP $MAINPID

TimeoutSec=0

RestartSec=2

Restart=always

然后重启服务

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

发现docker启动不了,报错。那只好恢复/usr/lib/systemd/system/docker.service 配置文件。

最终解决方案

我发现恢复/usr/lib/systemd/system/docker.service 之后,执行

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

还是会报错。

按理说恢复了之前的状态,应该不会报错。我查看了日志,systemctl status docker 显示操作太频繁。

那我灵光一闪,我是不是先把docker 关闭,然后再启动呢?

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl stop docker

# 等几秒
sudo systemctl start docker

docker服务启动成功,再测试一下登录,发现成功了。

总结

daemon.json 配置这个解决方法是对的,但是最后,最好是关闭docker服务,再启动。否则可能出现上面的配置不起作用的问题。

相关推荐
leisoo80977 小时前
100GBA股股票数据怎么存ClickHouseRedisMySQLJSON完整对比
大数据·linux·服务器·开发语言·python
梦梦代码精8 小时前
连锁品牌数字化:从门店扩张到用户资产运营的技术底座
大数据·人工智能·低代码·docker·开源·代码规范
青瓦梦滋8 小时前
传输层UDP/TCP协议
linux·网络·c++·网络协议·tcp/ip·udp
ltl9 小时前
机密计算:SGX、SEV-SNP、TDX 与 ARM CCA
linux
ltl9 小时前
互联与网络:NVLink、InfiniBand、RoCE 与国产替代
linux
码上上班9 小时前
tengine知识点
linux·服务器·centos
InfinitePlus11 小时前
Docker MySQL搭建一主一从
mysql·docker
雾时之林12 小时前
Linux--软件管理、源码包安装
linux·服务器·数据库
坐吃山猪13 小时前
Docker07-MySQL
mysql·docker·容器
Wzx19801214 小时前
python沙箱和docker沙箱你选对了吗?
开发语言·python·docker