Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am facing to an issue with Kong, i created my service and my route exactly like the 5min quickstart of the Kong's documentation but i only change some parameters to setup the service with my own api working on localhost:3000.

So there is my setup:

  • Kong running on docker (Docker is running on the same machine than my service)
  • http://localhost:3000/users which is my service always returning JSON {"status": "OK"}
  • there is what i did to create my service.

    I created my service with parameters :

    "name": "users", "url": "http://localhost:3000", "host": "127.0.0.1"

    then i created the Route with body:

    "hosts": [ "127.0.0.1"], "methods": ["GET"], "paths": ["/"], "name": "users"

    then i tried if everything is working with http://localhost:8080/users with header: "Host:127.0.0.1"

    and i got the reply:

    502 Bad Gateway : An invalid response was received from the upstream server

    The docker's Logs (this one hosting kong) :

    2019/03/04 09:28:36 [error] 36#0: *63824 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: kong, request: "GET /users HTTP/1.1", upstream: " http://127.0.0.1:3000/users ", host: "127.0.0.1"

    So we can see Kong trying to access the good endpoint '127.0.0.1:3000/' but can't access to it.

    Maybe Kong trying to access is own container localhost but i don't know, and i don't know how to fix it, maybe you can help me!

    You have indeed configured Kong to access its own container. In order to access services running on your actual machine (I assume Windows or macOS here), you can point the service to http://host.docker.internal:3000 instead. Additionally, I would leave out the host properties until you have connected correctly, and then add the restrictions back in again.

    See also this question: Dockererized Kong on windows giving "An invalid response was received from the upstream server"

    Kong running in a container is like it's having its own little VM (don't hit me, I know this is not quite true, but from a networking perspective, this works), and localhost for Kong is just that, the container. The host of the container, to Kong, is a separate host.

    As your service is running outside the container and the kong network, you enter your local IP instead of localhost.

    Example: http://192.168.1.10:3000

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .