Home > Back-end >  Why no_proxy must be specified for CURL to work in this scenario?
Why no_proxy must be specified for CURL to work in this scenario?

Time:08-25

Inside my virtual machine, I have the following docker-compose.yml file:

services:
  nginx:
    image: "nginx:1.23.1-alpine"
    container_name: parse-nginx
    ports:
      - "80:80"

  mongo-0:
    image: "mongo:5.0.6"
    container_name: parse-mongo-0
    volumes:
      - ./mongo-0/data:/data/db
      - ./mongo-0/config:/data/config

  server-0:
    image: "parseplatform/parse-server:5.2.4"
    container_name: parse-server-0
    ports:
      - "1337:1337"
    volumes:
      - ./server-0/config-vol/configuration.json:/parse-server/config/configuration.json
    command: "/parse-server/config/configuration.json"

The configuration.json file specified for server-0 is as follows:

{
  "appId": "APPLICATION_ID_00",
  "masterKey": "MASTER_KEY_00",
  "readOnlyMasterKey": "only",
  "databaseURI": "mongodb://mongo-0/test"
}

After using docker compose up, I execute the following command from the VM:

curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://localhost:1337/parse/classes/GameScore

The output is:

{"objectId":"yeHHiu01IV","createdAt":"2022-08-25T02:36:06.054Z"}

I use the following command to get inside the nginx container:

docker exec -it parse-nginx sh

Pinging parse-server-0 shows that it does resolve into a proper IP address. I then run the modified version of the curl command above changing localhost with that host name:

curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://parse-server-0:1337/parse/classes/GameScore

It gives me a 504 error like this:

...
        <title>504 DNS look up failed</title>
    </head>
    <body><div >
    <div ></div>
    <h1>504 DNS look up failed</h1>
    <p>The webserver reported that an error occurred while trying to access the website. Please return to the previous page.</p>
...

However if I use no_proxy as follows, it works:

no_proxy="parse-server-0" curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "X-Parse-Master-Key: MASTER_KEY_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://parse-server-0:1337/parse/classes/GameScore

The output is again something like this:

{"objectId":"ICTZrQQ305","createdAt":"2022-08-25T02:18:11.565Z"}

I am very perplexed by this. Clearly, parse-server-0 is reachable with ping. How can it then throws a 504 error without using no_proxy? The parse-nginx container is using default settings and configuration. I do not set up any proxy. I am using it to test the curl command from another container to parse-mongo-0. Any help would be greatly appreciated.


The contents of /etc/resolv.conf is:

nameserver 127.0.0.11
options edns0 trust-ad ndots:0

Running echo $HTTP_PROXY inside parse-nginx returns:

http://10.10.10.10:8080

This value is null inside the VM.

CodePudding user response:

Your proxy server doesn't appear to be running in this docker network. So when the request goes to that proxy server, it will not query the docker DNS on this network to resolve the other container names.

If your application isn't making requests outside of the docker network, you can remove the proxy settings. Otherwise, you'll want to set no_proxy for the other docker containers you will be accessing.

CodePudding user response:

Please check the value of echo $http_proxy. Please note the downcase here. If this value is set, that means curl is configured to use the proxy. You're getting 504 while DNS resolution most probably because your parse-nginx container isn't able to reach the ip 10.10.10.10. And specifying no_proxy tells it to ignore the http_proxy env var (overriding it) and make the request without any proxy.

  • Related