Tried looking around but couldn't find anything close to what I need.
I have a docker-compose file with a docker container (web
) that uses another container's IP (api
) in its environment variable by resolving the hostname:
version: '3'
services:
web:
build: ../client/
ports:
- "5000:5000"
- "3000:3000"
environment:
REACT_APP_API_DEV: http://api:8000/server/graphql
api:
build: ../server/
env_file:
- server_variables.env
ports:
- "8000:8000"
redis:
image: "redis:alpine"
My issue is that web
doesn't resolve this variable when it's running. I can ping api
just fine inside the web
container but http://api:8000
doesn't resolve properly. I also tried making HOST=api the variable and building the URI manually but that doesn't work either.
EDIT: I added a complete docker-compose.yml file for reference. I can curl
the api
just fine from inside the web
container, but my app can't seem to resolve it properly. I'm using NodeJS and React
You have to link them using
network
Alright, I found the issue. Apparently, my
web
container was fetching fromapi
with thehttp://api:8000
URI but my browser doesn't know whatapi
is (only the containers do).I followed the stuff suggested in here to resolve the hostname on my machine and it worked out.