我正在使用docker compose在自己的机器上设置三个docker容器:
portal
)gateway
)auth
)我还拥有在公司防火墙后运行的大量服务。
在大多数情况下,
gateway
将请求防火墙后的资源,因此我已将docker容器配置为通过可访问其他服务的鱿鱼代理来代理请求。但是,不应代理对我的本地auth
服务和其他本地服务的请求。因此,我具有以下 docker 代理配置(请注意noProxy
设置):~/.docker/config.json
...
"proxies": {
"default": {
"httpProxy": "http://172.30.245.96:3128",
"httpsProxy": "http://172.30.245.96:3128",
"noProxy": "auth,localhost,127.0.0.1,192.168.0.1/24"
}
}
...
通过上述设置,
portal
请求 do 通过浏览器使用gateway
直接转到http://192.168.0.15/foo
,但是当gateway
使用auth
提出对http://auth:3001/bar
的请求时,它们不会直接进入auth
而是通过-我在努力避免。我可以看到auth请求是通过鱿鱼代理错误通过代理发送的:
<p>The following error was encountered while trying to retrieve the URL: <a href="http://auth:3001/token">http://auth:3001/bar</a></p>
如何使用docker服务名称(例如
noProxy
)设置docker容器以遵守auth
设置?在我看来,从gateway
到auth
的请求被误认为是172.30.245.96:3128
代理,导致它无法正常工作。谢谢
最佳答案
您的Docker配置看起来不错,但是您的主机不理解如何解析名称auth
。根据给定的IP(192.168.x.x),我假设您正在尝试从主机访问容器服务。在主机的auth
中添加/etc/hosts
条目(如果是Windows,则为C:\Windows\System32\Drivers\etc\hosts
)。
查看Linked docker-compose containers making http requests了解更多详细信息。
如果遇到从容器内部获取服务的问题,请查看docker-compose resolve hostname in url作为示例。
关于docker - 如何使用no_proxy设置设置Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57503445/