一、添 docker子配置档设置
1、创建目录
mkdir /etc/systemd/system/docker.service.d
2、创建http-proxy.conf文件,增加以下内容
cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://192.168.0.2:8118"
Environment="HTTPS_PROXY=http://192.168.0.2:8118"
Environment="NO_PROXY=localhost,127.0.0.1,registry.onlymin.com,reg.onlymin.com"
EOF
或
cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://192.168.1.91:3128" "NO_PROXY=localhost,127.0.0.1"
EOF
3、Daemon重新reload 并重启docker
systemctl daemon-reload
systemctl restart docker
4、检查变量是否加载
systemctl show docker --property Environment
Environment="HTTP_PROXY=http://192.168.1.91:3128" "NO_PROXY=localhost,127.0.0.1"
5、取消代理
rm /etc/systemd/system/docker.service.d/http-proxy.conf -rf
systemctl daemon-reload
systemctl restart docker
systemctl show docker --property Environment
二、通过修改 docker.service配置设置
1、编辑docker.service
vim /usr/lib/systemd/system/docker.service
在[Service]配置项内添加以下内容:
Environment="HTTP_PROXY=代理url"
Environment="HTTPS_PROXY=代理url"
2、重启docker.service服务
systemctl daemon-reload
systemctl restart docker.service
3、最后测试docker是否可以联网
docker run -it openshift/hello-openshift