docker使用http服务及国内镜像加速
由于docker默认https提供服务,即使是http依旧会强制使用https链接。使用harbor建立http docker服务器,本地拉取远程镜像。假设目标http服务器为。
·
文章目录
项目场景:
使用harbor建立http docker服务器,本地拉取远程镜像。
问题描述
拉取镜像时报错no response to ...
原因分析:
由于docker默认https提供服务,即使是http依旧会强制使用https链接。
解决方案 1:
添加daemon.json文件
$ sudo touch /etc/docker/daemon.json
编辑文件添加http服务器地址
# /etc/docker/daemon.json
{
"insecure-registries" : [
"http://harbor.qq.com",
"http://harbor.baidu.com:5300"
],
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
其中registry-mirrors为国内加速镜像服务器。
解决方案 2:
查找docker service文件地址
使用systemctl status docker.service
@debian:~/bing_ws/humble_docker$ systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-12-12 21:07:19 CST; 1 day 22h ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1423968 (dockerd)
Tasks: 27
Memory: 63.7M
CPU: 2min 2.120s
CGroup: /system.slice/docker.service
└─1423968 /usr/sbin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
添加指定docker服务器http地址
假设目标http服务器为http://harbor.qq.com,做如下修改,
多个地址可以直接加在后边。
vim /lib/systemd/system/docker.service
# 修改为
# ExecStart=/usr/sbin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock $DOCKER_OPTS
ExecStart=/usr/sbin/dockerd -H fd:// --insecure-registry=harbor.qq.com --insecure-registry=harbor.baidu.com --containerd=/run/containerd/containerd.sock $DOCKER_OPTS
重启docker服务
$ systemctl daemon-reload
$ systemctl restart docker.service
验证修改是否成功
$ docker info
--- output
Client:
Context: default
Debug Mode: false
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 25
Server Version: 20.10.5+dfsg1
...
Kernel Version: 5.10.0-19-amd64
Operating System: Debian GNU/Linux 11 (bullseye)
OSType: linux
Architecture: x86_64
CPUs: 20
Total Memory: 15.42GiB
Name: debian
...
Docker Root Dir: /var/lib/docker
Debug Mode: false
Username: binglee75
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
harbor.qq.com
harbor.baidu.com:5300
127.0.0.0/8
Registry Mirrors:
https://docker.mirrors.ustc.edu.cn/
https://registry.docker-cn.com/
Live Restore Enabled: false
WARNING: Support for cgroup v2 is experimental
更多推荐
所有评论(0)