I'm wondering how to fix this problem! Essentially the dynamic routing via service name on the default Docker network is not working. :(
I had considered making it use a static IP but that may be more work than fixing the original issue.
docker-compose.yml
version: "3.8"
services:
client:
build: client
ports: [3000]
depends_on:
- server
volumes:
- ./client:/app
mongodb:
image : mongo
environment:
- PUID=1000
- PGID=1000
ports: [27017]
restart: unless-stopped
volumes:
- ./mongodb/database:/data/db
server:
build: server
ports: [5000]
restart: always
depends_on:
- mongodb
volumes:
- ./server:/app
If I do this ping test from the client it will work via the browser
http://0.0.0.0:49246/ping
However, I really want it to work in this approach here
http://server:5000/ping
Help? Thank you!
CodePudding user response:
Web app code runs in the browser, not the server hosting the files. The browser is typically running on the host.
It sounds like you want the server to map a known port on the host. Try using this to map host port 5000 to the server
container port 5000...
server:
build: server
ports:
- "5000:5000"
# etc
and connect on http://localhost:5000
in your web app code.
See https://docs.docker.com/compose/compose-file/compose-file-v3/#ports
If you're wanting your web app to proxy requests (for example using the Create React App proxy
configuration), you would use the internal host name since this action is performed by the client
service.
"proxy": "http://server:5000"