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