neurobagel / federation-api

REST API for query federation over multiple Neurobagel graph databases
https://federate.neurobagel.org
MIT License
0 stars 0 forks source link

a locally running n-API on the host cannot be reached under localhost from f-API inside a docker container #47

Closed surchs closed 11 months ago

surchs commented 11 months ago

Dave encountered this today, leading to some head scratching:

Being the good user I am, I follow the docs precisely:

  1. My computer (host) runs a n-API on port 8000. All is well there
  2. I now also launch a f-API locally, inside a docker container - as the docs tell me.
  3. I tell my f-API about my already running local n-API like so, as the docs tell me:
[
    {
        "NodeName": "Sebs node",
        "ApiURL": "http://localhost:8000"
    }
]
  1. The /nodes endpoint of my f-API lists all the nodes as expected
  2. All of the query endpoints (instance or query) in the f-API break with internal server error and I get no results!
  3. If shut down f-API in the docker container and just run it on bare metal (venv) with the same config

-> :cry:

The problem is that localhost isn't my "host" inside the docker container, so I cannot reach my local n-API. Because we haven't fixed neurobagel/federation-api#38 yet, my local node "failing" leads to the entire f-API failing. Finally, if I run this on bare metal (venv), all is well, because "localhost" makes sense again.

btw: the reason this all works in prod is because we don't refer to any of our nodes with localhost but instead use their public IPs.

To support a truly local deployment, we can use the docker --add-host feature: https://docs.docker.com/engine/reference/commandline/run/#add-host

extra_hosts:
    - "host.docker.internal:host-gateway"

and then change the local node config to

[
    {
        "NodeName": "Sebs node",
        "ApiURL": "http://host.docker.internal:8000"
    }
]

TODO:

alyssadai commented 11 months ago

for your interest, I can confirm that at least on Windows, changing the local nodes config to "http://host.docker.internal:8000" indeed seems to be sufficient (extra_hosts does not need to be manually added to the docker-compose.yml, it seems).

that said, to make these files interoperable we should definitely add it just in case :)

surchs commented 7 months ago

:rocket: Issue was released in v0.1.0 :rocket: