I took this example https://github.com/paulc4/microservices-demo and I created 3 docker images from it, with the following Dockerfiles:
springdocker-registration:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar
EXPOSE 1111
ENTRYPOINT exec java -jar /app.jar registration
springdocker-accounts:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar
EXPOSE 2222
ENTRYPOINT exec java -jar /app.jar accounts
springdocker-web:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar
EXPOSE 3333
ENTRYPOINT exec java -jar /app.jar web
If I run the three images separately everything works ok, the web and accounts services register to the registration service (which is an implementation of the eureka registry) and I can use my application. However when using docker-compose with the following docker-compose.yml file
version: "3.4"
services:
registration:
image: springdocker-registration
ports:
- "1111:1111"
accounts:
image: springdocker-accounts
ports:
- "2222:2222"
links:
- registration
depends_on:
- registration
web:
image: springdocker-web
ports:
- "3333:3333"
depends_on:
- registration
- accounts
links:
- registration
the services web and accounts are not able to register to the registration service. Here are the configuration files for the applications:
registration-server.yml:
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:1111/eureka/
server:
port: 1111
spring:
thymeleaf:
enabled: false
accounts-server.yml:
spring:
application:
name: accounts-service
freemarker:
enabled: false
thymeleaf:
cache: false
prefix: classpath:/accounts-server/templates/
error:
path: /error
server:
port: 2222
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka
instance:
leaseRenewalIntervalInSeconds: 5
preferIpAddress: true
web-server.yml
spring:
application:
name: web-service
freemarker:
enabled: false
thymeleaf:
cache: false
prefix: classpath:/web-server/templates/
error:
path: /error
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka
instance:
leaseRenewalIntervalInSeconds: 5
preferIpAddress: true
server:
port: 3333
I can post the full console log of docker-compose up but I think this is the interesting point:
1: ERROR RedirectingEurekaHttpClient - Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
1: ERROR DiscoveryClient - DiscoveryClient_WEB-SERVICE/e3b5e6b3396c:web-service:3333 - was unable to refresh its cache! status = Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Comment From: ryanjbaxter
The problem is this
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka
It is pointing to localhost and Eureka is no longer running on localhost, localhost in this case is the individual containers. The containers are linked together so you can just change this to
eureka:
client:
serviceUrl:
defaultZone: http://registration:1111/eureka
and I think that will fix your problem.
Comment From: bndynet
That's my wanted.
Comment From: dineschandgr
it worked. thank you
Comment From: shnkar007
Even after I change to the services name, the clients are not registering