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

相关推荐
K***430638 分钟前
IDEA+Docker一键部署项目SpringBoot项目
spring boot·docker·intellij-idea
xu_yule6 小时前
Linux_12(进程信号)内核态和用户态+处理信号+不可重入函数+volatile
linux·运维·服务器
虾..6 小时前
Linux 环境变量&&进程优先级
linux·运维·服务器
i***t9196 小时前
Linux下MySQL的简单使用
linux·mysql·adb
偶像你挑的噻6 小时前
11-Linux驱动开发-I2C子系统–mpu6050简单数据透传驱动
linux·驱动开发·stm32·嵌入式硬件
小雪_Snow6 小时前
CentOS 7 测试 docker 镜像源
docker·centos
稚辉君.MCA_P8_Java7 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
郝学胜-神的一滴9 小时前
Linux命名管道:创建与原理详解
linux·运维·服务器·开发语言·c++·程序人生·个人开发
宾有为9 小时前
【Linux】Linux 常用指令
linux·服务器·ssh
wdfk_prog9 小时前
[Linux]学习笔记系列 -- [block]bio
linux·笔记·学习