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服务,再启动。否则可能出现上面的配置不起作用的问题。

相关推荐
比昨天多敲两行23 分钟前
Linux基础开发工具(下)
linux·运维·服务器
笨笨饿2 小时前
69_如何给自己手搓一个串口
linux·c语言·网络·单片机·嵌入式硬件·算法·个人开发
cn_lyg2 小时前
Linux的入门级常用操作命令
linux·运维·服务器
就叫飞六吧3 小时前
TOML vs YAML:为什么 Cargo 选择 TOML?
linux·运维·服务器
IMPYLH3 小时前
Linux 的 test 命令
linux·运维·服务器·chrome·bash
xrui584 小时前
2026实战:深度解析 Gemini 3.1 镜像站函数调用在自动化运维工单中的应用
linux·服务器·网络
HackTwoHub4 小时前
Linux 内核史诗级本地提权 全网深度复现、原理完整分析( CVE-2026-31431)
linux·运维·安全·web安全·网络安全·代码审计·安全架构
她说彩礼65万4 小时前
C语言 文件
linux·服务器·c语言
txg6665 小时前
自动驾驶领域热点简报(2026-04-26 ~ 2026-05-03)
linux·人工智能·自动驾驶
二哈赛车手5 小时前
新人笔记---ES和kibana启动问题以及一些常用的linux的错误排查方法,以及ES,数据库泄密解决方案[超详细]
java·linux·数据库·spring boot·笔记·elasticsearch