docker的3种网络代理配置
dockerd代理
docker pull由守护进程dockerd执行,代理配置dockerd中。
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/proxy.conf
[Service]
Environment="HTTP_PROXY=http://xxx:xxx"
Environment="HTTPS_PROXY=http://xxx:xxx"
Environment="NO_PROXY=localhost,127.0.0.1,.xxx.com"
systemctl daemon-reload
systemctl restart docker
container代理
容器运行阶段和docker login走代理,Docker 17.07及以上版本生效。
vim ~/.docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://xxx:xxx",
"httpsProxy": "http://xxx:xxx",
"noProxy": "localhost,127.0.0.1,.xxx.com"
}
}
}
docker build代理
docker build . --build-arg "HTTP_PROXY=http://xxx:xxx" --build-arg "HTTPS_PROXY=http://xxx:xxx" --build-arg "NO_PROXY=localhost,127.0.0.1,.xxx.com" -t xxx:xxx