Unable to fetch link_token in Frontend UI: Connection refused to http://localhost:8000
jcranfordupgrade opened this issue · 2 comments
I tried running docker-compose up node -d
on Mac. When I open http://localhost:3000 on my host, I get an error in the UI page similar to #405.
Unable to fetch link_token: please make sure your backend server is running and that your .env file has been configured with your PLAID_CLIENT_ID and PLAID_SECRET.
However, it seems like the root cause and workaround might be different, and may require a fix in docker-compose.yml.
I did some googling, and it seems newer versions of Docker frown on using localhost
for connections between containers. Docker seems to want people to use something else:
- Use container name (e.g.
start-node-1
) to point to a specific container. - Use
host.docker.internal
to point to the host's localhost (i.e. not the container's localhost). - Use
extra_hosts
? - Probably other solutions?
To workaround the issue, I edited docker-compose.yml to set the REACT_APP_API_HOST
environment variable in frontend service. After restarting docker-compose, the Frontend UI worked.
Launch Link
Both of these workarounds worked for me:
REACT_APP_API_HOST=http://host.docker.internal:8000
REACT_APP_API_HOST=http://start-node-1:8000
The second option is specific to using the node container. The first option might be more generic to work with other implementations of the API container (e.g. Java, Go, etc).
The versions I used:
% uname -a
Darwin J5R6K724LM-jcranford 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64
% docker-compose --version
Docker Compose version v2.18.1
% docker --version
Docker version 20.10.23, build 715524332f
Steps to reproduce the problem:
- Start API and Frontend containers:
docker-compose up node -d
- From host, verify Frontend container is reachable via
localhost
:curl http://localhost:3000
- From host, verify API container is reachable via
localhost
:curl http://localhost:8000
- From host, open Frontend URL in a browser:
http://localhost:3000/
=> Displays this error within the page
Unable to fetch link_token: please make sure your backend server is running and that your .env file has been configured with your PLAID_CLIENT_ID and PLAID_SECRET.
Steps to diagnose the problem:
- Open a shell into the Frontend container:
docker exec -it start-frontend-1 sh
- Install curl:
apk add curl
- Install nslookup:
apk add net-tools
- Within the Frontend container, verify Frontend URL is reachable via localhost:
curl http://localhost:3000
- Within the Frontend container, verify API URL is NOT reachable via localhost:
curl http://localhost:8000
curl: (7) Failed to connect to localhost port 8000 after 0 ms: Couldn't connect to server
- Within the Frontend container, verify API URL is reachable via start-node-1:
curl http://start-node-1:8000
=> It works! - Within the Frontend container, verify API URL is reachable via host.docker.internal:
curl http://host.docker.internal:8000
=> It works!
Steps to apply the workaround:
- Edit docker-compose.yml
- For
frontend
service, set environment variableREACT_APP_API_HOST=http://start-node-1:8000
- Restart containers:
docker-compose restart
- From host, open Frontend URL in a browser:
http://localhost:3000/
=> It works!
Launch Link
Thanks for the report! I believe the issue here is the command used to start the Quickstart. When I tried starting the quickstart as you describe, using docker-compose up node -d
, the command failed like you describe. When I tried starting the Quickstart according to the directions in the README, which specify using make up language=node
(or whatever other language you want to use) it succeeded.