Spring Cloud Netflix and Docker Compose - can't register services with eureka
I am trying to use docker-compose to run 2 simple services locally (Ubuntu): eureka server and config server (which is also eureka client). Both of them have simple docker files that run java -jar
, expose their ports, and individually work fine. I also tried adding eureka.client.service-url.defaultZone=http://company-service-discovery:8761/eureka
to see if it would register and it worked.
My config server cannot successfully register with the eureka server and I googled it and nothing I saw helped me solve this problem.
As per the docker composing documentation https://docs.docker.com/compose/networking/ :
By default, Compose sets up one network for your application. Each container for a service joins the network by default and is accessible to and discoverable by other containers on that network by a hostname that is identical to the container name.
The following example web
should be able to use postgres://db:5432
to communicate with the database.
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
I used the same method to configure my services, but my config server gets rejected when trying to register:
docker-compose.yml
version: '3.3'
services:
company-service-discovery:
build: company-service-discovery/
ports:
- "8761:8761"
company-config-server:
build: company-config-server/
ports:
- "8888:8888"
links:
- company-service-discovery
config server bootstrap.yml
server:
port: 8888
management:
security:
enabled: false
spring:
application:
name: company-config-server
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
include: native
eureka:
client:
service-url:
defaultZone: http://company-service-discovery:8761/eureka
eureka server bootstrap.yml
spring:
application:
name: company-service-discovery
server:
port: 8761
management:
security:
enabled: false
An exception
2017-07-26 14:25:05.738 WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2017-07-26 14:25:05.739 WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COMPANY-CONFIG-SERVER/365d20275ab0:company-config-server:8888 - registration failed Cannot execute request on any known server
Question
Is there something wrong with my configuration? How can I get it to work?
Let me know if any information is missing, I will happily provide any information I can.
source to share
Add the config defaultZone
to the properties of the Eureka server too (and change service-url
to serviceUrl
the bootstrap.yml config on the server ).
eureka server bootstrap.yml
spring:
application:
name: company-service-discovery
eureka:
client:
serviceUrl:
defaultZone: http://company-service-discovery:8761/eureka
server:
port: 8761
management:
security:
enabled: false
source to share
Many thanks. This post solved my problem - connecting eureka client to eureka server using docker. After 2 days of searching, everything worked. I'm in tears.
So basically -
You must use the following in eureka client application.properties/.yml
eureka.client.service-url.defaultZone = http: // eureka-server: 8761 / eureka
and in docker-compose.yml your eureka service name should match the - url hostname, in my case it is eureka-server
source to share