Docker无法加载代理环境变量

时间:2019-10-25 08:12:48

标签: linux docker centos7

我在Docker上安装了18.06.3-ceCentOs 8

我的系统位于防火墙后面,因此我尝试通过使用适当的设置在http-proxy中添加/etc/systemd/system/docker.service.d文件来编辑代理设置。

[Service]
Environment="HTTP_PROXY=http://my_proxy:port"
Environment="HTTPS_PROXY=http://my_other_proxy:port"
Environment="NO_PROXY=<ANOTHER_PROXY>"

但是,即使在systemctl daemon-reloadsystemctl restart docker之后,“环境”设置似乎也没有生效。

当我尝试

  

systemctl show --property环境docker

我只看到

  

环境=

没有任何值。

我是LinuxDocker的新手,所以不确定为什么会这样。尽管代理地址可能无法正常工作,但我希望至少能在Environment属性中看到这些值。

1 个答案:

答案 0 :(得分:2)

您应该使用.json文件而不是使用ENV vars配置Docker客户端

  

Doc:https://docs.docker.com/network/proxy/

On the Docker client, create or edit the file ~/.docker/config.json in the home directory of the user which starts containers. Add JSON such as the following, substituting the type of proxy with httpsProxy or ftpProxy if necessary, and substituting the address and port of the proxy server. You can configure multiple proxy servers at the same time.

You can optionally exclude hosts or ranges from going through the proxy server by setting a noProxy key to one or more comma-separated IP addresses or hosts. Using the * character as a wildcard is supported, as shown in this example.

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://your_proxy:port",
     "httpsProxy": "https://your_other_proxy:port",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}
Save the file.

When you create or start new containers, the environment variables are set automatically within the container.