Iv created two Springboot applications that Iv dockerized and created local containers. When I run the applications locally through intellij on my machine they work ok. Application A, on localhost:8080 has a Spring WebClient with a baseUrl localhost:8081 configured to call Application B running on port 8081. This works great.
The problem starts when I add those container to a docker compose file and spin then up
version: "3.7"
services:
appa:
image: application/myapp:1
hostname: localhost
ports:
- 8080:8080
appb:
image: application/myapp:2
hostname: localhost
ports:
- 8081:8081
I can hit localhost:8080 from the browser, but when the client in the application tried to call application b using the WebClient, it falls over with
Error has been observed at the following site(s):
| |_ checkpoint ⇢ Request to GET
http://localhost:8081/api/feed [DefaultWebClient]
| Stack trace:
| Caused by: java.net.ConnectException: finishConnect(..) failed:
Connection refused
I can hit both apps from the browser or curl, but it seems they cant communicate internally inside the docker containers
Any help appreciated