环境:
centos7已配置代理全局模式,使用的配置文件是/etc/profile
但是docker容器中无法使用外部配置
为何呢:
由于外部环境使用的是/user/local/share/gtfxxxxxxx/config.json
详见博客:https://blog.csdn.net/Beyond_F4/article/details/106575338
而Docker守护程序在其启动环境中使用HTTP_PROXY,HTTPS_PROXY和NO_PROXY环境变量来配置HTTP或HTTPS代理行为。 所以不能使用config.json文件配置这些环境变量。
解决办法:
分三步
1、为服务器docker创建system目录
2、创建配置文件
3、使之生效
具体如下:
1、创建如下目录
# 创建系统目录
mkdir -p /etc/systemd/system/docker.service.d
2、根据个人需求的代理模式情况分别创建对应的文件
如果使用的是http代理
vi /etc/systemd/system/docker.service.d/http-proxy.conf
并在配置文件中加入http环境变量
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
如果使用的是https代理
vi /etc/systemd/system/docker.service.d/https-proxy.conf
并在配置文件中加入https环境变量
[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"
如果不需要通过代理访问,则在上面配置中增加NO_PROXY环境变量
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,*.a.com"
或者
[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,*.a.com"
3、使之生效
systemctl daemon-reload
4、重启服务
systemctl restart docker