George
George

Reputation: 51

How to set up docker with no_proxy settings

I'm setting up three docker containers on my own machine using docker compose:

I also have a bunch of services already running behind a corporate firewall.

For the most part, gateway will request resources behind the firewall, so I have configured docker containers to proxy requests through a squid proxy with access to the additional services. However requests to my local auth service, and other local services should not proxied. As such, I have the following docker proxy configuration (note the noProxy settings):

~/.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"
        }
    }
    ...

With the above setup, portal requests do go directly to gateway through the browser using http://192.168.0.15/foo, but when gateway makes requests to auth using http://auth:3001/bar, they do not go directly to auth but instead do go through the proxy - which I am trying to avoid.

I can see the auth request is sent through the proxy with the squid proxy errors:

<p>The following error was encountered while trying to retrieve the URL: <a href="http://auth:3001/token">http://auth:3001/bar</a></p>

How can I set up the docker containers to respect the noProxy setting using docker service names like auth? It appears to me that the request from gateway to auth is mistakingly being proxed through 172.30.245.96:3128, causing it to not work. Thanks

Upvotes: 5

Views: 23520

Answers (1)

Pete Torres
Pete Torres

Reputation: 33

Your Docker configuration seems fine, but your host doesn't understand how to resolve the name auth. Based on the IP given (192.168.x.x), I'll assume that you're attempting to reach the container service from the host. Add an entry for auth into your host's /etc/hosts (C:\Windows\System32\Drivers\etc\hosts if on Windows).

Take a look at Linked docker-compose containers making http requests for more details.
If you run into issues reaching services from within the container, check docker-compose resolve hostname in url for an example.

Upvotes: 3

Related Questions