1、docker pull/docker push超时,需要更改docker服务整体走proxyAddress,将以下proxyAddress更改为实际地址,即可解决docker pull超时的问题:
1 2 3 4 | vim /etc/systemd/system/docker .service.d /http-proxy .conf
:! mkdir -p %:h
|
1 2 3 4 | [Service]
Environment= "HTTP_PROXY=proxyAddress"
Environment= "HTTPS_PROXY=proxyAddress"
Environment= "NO_PROXY=localhost,127.0.0.1,*.xyz,*.cn"
|
重启docker
1 | systemctl daemon-reload && systemctl restart docker
|
有如下输出即为设置成功:
1 2 3 | HTTP Proxy: proxyAddress
HTTPS Proxy: proxyAddress
No Proxy: localhost,127.0.0.1,*.xyz,*.cn
|
优点:
无需更改daemon.json中的registry-mirrors镜像加速地址,仍然为registry.hub.docker.com;
直接docker pull/docker push时走docker服务的proxyAddress
2、自定义镜像仓库地址,https://registry.hub.docker.com可为自定义加速域名
1 | vim /etc/docker/daemon .json
|
1 2 3 4 5 | {
"registry-mirrors" : [
"https://registry.hub.docker.com"
]
}
|
修改hostname
增加docker官方registry的hostname:
1 2 3 | 34.226.69.105 registry.hub.docker.com
54.196.99.49 registry.hub.docker.com
3.219.239.5 registry.hub.docker.com
|
1 2 3 | 34.226.69.105 registry-1.docker.io
54.196.99.49 registry-1.docker.io
3.219.239.5 registry-1.docker.io
|
重启docker
1 | systemctl daemon-reload && systemctl restart docker
|
其他可用镜像仓库地址
1 2 3 4 5 6 7 8 | {
"registry-mirrors" : [
"https://gallery.ecr.aws" ,
"https://dh-mirror.gitverse.ru" ,
"https://www.lmirror.top" ,
"https://hub.atomgit.com"
]
}
|
3、可选,设置容器内部使用proxy环境变量,适用于容器内部需要走proxyAddress的场景
1 | vim ~/.docker /config .json
|
1 2 3 4 5 6 7 8 | {
"proxies" : {
"default" : {
"httpProxy" : "proxyAddress" ,
"httpsProxy" : "proxyAddress"
}
}
}
|
与容器内部环境变量的映射关系:
httpProxy -> HTTP_PROXY
httpsProxy -> HTTPS_PROXY