I tried to implement an example of Spring Boot Microservice examples. I have a problem in docker-compose file.
Eureka server and api gateways throws an issue defined below while there is no issue in config server.
Here is the issue : com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Here is the code snippets for config server.
configserver:
image: configserver
container_name: configServer
build:
context: ./configserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://localhost:9191"
CONFIGSERVER_PORT: "9191"
ports:
- "9191:9191"
networks:
backend:
aliases:
- "configserver"
Here is the code snippets for eureka server
eurekaserver:
image: eurekaserver
ports:
- "8761:8761"
build:
context: ./discoveryserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://localhost:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://localhost:8761/eureka/"
EUREKASERVER_PORT: "8761"
depends_on:
configserver:
condition: service_started
networks:
backend:
aliases:
- "eurekaserver"
Here is the code snippets for api gateway server.
gatewayserver:
image: gatewayserver
ports:
- "8600:8600"
build:
context: ./api-gateway
dockerfile: Dockerfile
environment:
PROFILE: "default"
SERVER_PORT: "8600"
CONFIGSERVER_URI: "http://localhost:9191"
EUREKASERVER_URI: "http://localhost:8761/eureka/"
EUREKASERVER_PORT: "8761"
CONFIGSERVER_PORT: "9191"
depends_on:
configserver:
condition: service_started
eurekaserver:
condition: service_started
networks:
backend:
aliases:
- "gateway"
Here is all docker-compose.yml : Link
Services are no longer running on localhost.
So change:
EUREKASERVER_URI: "http://localhost:8761/eureka/"
To corresponding service container name, take Eureka server for instance:
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
See Github issue.