分类
Docker代理一共分为3类
Docker代理: 控制docker pull等命令的代理
container代理: docker run 启动容器的时候,容器里面使用的代理服务器
builder代理: docker build时的代理
配置Docker代理
mkdir -p /etc/systemd/system/docker.service.d
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/proxy.conf
# 写入以下内容
[Service]
Environment="HTTP_PROXY=http://192.168.14.254:1080/"
Environment="HTTPS_PROXY=http://192.168.14.254:1080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
# 重启
systemctl daemon-reload
systemctl restart docker
配置container代理
vim ~/.docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://192.168.14.254:1080/",
"httpsProxy": "http://192.168.14.254:1080/",
"noProxy": "localhost,127.0.0.1,.example.com"
}
}
}
# 重启docker进程
build 代理
docker build . \
--build-arg "HTTP_PROXY=http://192.168.14.254:1080" \
--build-arg "HTTPS_PROXY=http://192.168.14.254:1080" \
--build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" \
-t your/image:tag