我在Docker
上安装了18.06.3-ce
版CentOs 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-reload
和systemctl restart docker
之后,“环境”设置似乎也没有生效。
当我尝试
systemctl show --property环境docker
我只看到
环境=
没有任何值。
我是Linux
和Docker
的新手,所以不确定为什么会这样。尽管代理地址可能无法正常工作,但我希望至少能在Environment
属性中看到这些值。
答案 0 :(得分:2)
您应该使用.json文件而不是使用ENV vars配置Docker客户端
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.