I'm trying to run a full-stack application using the docker-compose file. However, back-end(SpringBoot) and front-end(ReactJs) containers can not communicate with each other using the service name.
I know that containers can communicate in user-defined bridge networks. my back-end connects to the database using db:5432 address. However, when I try to make a get request from frontend to the back-end: example: http://back-end:5055/getLogs?page=0
It is not working -> net::ERR_NAME_NOT_RESOLVED
So, Frontend couldn't make any requests to the backend.
If I expose ports from back-end and use http://localhost:5055/getLogs?page=0 everything works fine. However, I want to expose only front-end port to the user and the other stuff (back-end/DB) I want it to be isolated.
How to set up communication between these two???
docker-compose file
services:
db:
... env vars
networks:
- my-net
back-end:
image: back/preproduction:0.0.1
networks:
- my-net
front-end:
image: front/preproduction:0.0.1
ports:
- "80:3055"
networks:
- my-net
... volumes
networks:
my-net:
driver: bridge