When I start Eureka and Zuul independently via Spring-Boot runnable jar files, everything seems to work fine. But when I try to run each in a Docker container and connect them with Docker-Compose, the Zuul gateway is not able to find the Eureka server.
docker-compose.yml:
version: '3.6'
services:
eureka-serviceregistry:
container_name: serviceregistry
build: ./ServiceRegistry
ports:
- "8761:8761"
hostname: serviceregistry
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
zuul-edgeservice:
container_name: gateway
build: ./ServiceGateway
ports:
- "8080:8080"
hostname: gateway
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
Eureka Dockerfile:
FROM openjdk:8-jdk-alpine
# Add Spring Boot app.jar to Container
COPY /build/libs/ServiceRegistry-0.0.1-SNAPSHOT.jar /usr/local/ServiceRegistry.jar
EXPOSE 8761
# Fire up our Spring Boot app by default
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /usr/local/ServiceRegistry.jar" ]
Eureka application.properties:
server.port=8761
spring.application.name=EurekaServiceRegistry
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.hostname=EurekaServiceRegistry
logging.level.com.netflix.eureka=INFO
logging.level.com.netflix.discovery=INFO
Eureka Spring-Boot class:
@EnableEurekaServer
@SpringBootApplication
public class QQServiceRegistry {
public static void main(String[] args) {
SpringApplication.run(QQServiceRegistry.class, args);
}
}
Zuul Dockerfile:
FROM openjdk:8-jdk-alpine
# Add Spring Boot app.jar to Container
COPY /build/libs/ServiceGateway-0.0.1-SNAPSHOT.jar /usr/local/ServiceGateway.jar
EXPOSE 8080
# Fire up our Spring Boot app by default
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /usr/local/ServiceGateway.jar" ]
Zuul application.properties:
zuul.routes.auth.path=/enterprise_service/**
zuul.routes.auth.service-id=ENTERPRISE_SERVICE
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
Zuul Spring-Boot class:
@EnableZuulProxy
@SpringBootApplication
public class ServiceGateway {
public static void main(String[] args) {
SpringApplication.run(ServiceGateway.class, args);
}
}
Root build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
targetCompatibility = 1.8
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications ('mavenJava')
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactoryPublish {
dependsOn assemble
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.M8'
}
}
repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
bootJar {
launchScript()
}
}
Eureka sub-project gradle file:
group = 'my.company.service.infrastructure.registry'
version = '0.0.1-SNAPSHOT'
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
}
Zuul sub project gradle file:
group = 'my.company.service.infrastructure.gateway'
version = '0.0.1-SNAPSHOT'
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
}
And in the Zuul log, this error pattern over and over as it tries to register with Eureka:
2018-04-11 15:38:20.136 INFO 6 --- [nfoReplicator-0] >com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/gateway: >registering service... 2018-04-11 15:38:20.139 ERROR 6 --- [nfoReplicator-0] >c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: >Connection refused (Connection refused) at >com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4>Handler.java:187) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1] at >com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEn>codingFilter.java:123) ~[jersey-client-1.19.1.jar!/:1.19.1] at >com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFil>ter.java:27) ~[eureka-client-1.8.6.jar!/:1.8.6] at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client->1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~>>[jersey-client-1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~>[jersey-client-1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) >~[jersey-client-1.19.1.jar!/:1.19.1] at >com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.re>gister(AbstractJerseyEurekaHttpClient.java:56) ~[eureka-client->1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpCli>ent.execute(MetricsCollectingEurekaHttpClient.java:73) ~[eureka-client->1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.ex>ecuteOnNewServer(RedirectingEurekaHttpClient.java:118) ~[eureka-client->1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.ex>ecute(RedirectingEurekaHttpClient.java:79) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.exec>ute(RetryableEurekaHttpClient.java:119) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.exec>ute(SessionedEurekaHttpClient.java:77) [eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) [eureka-client-1.8.6.jar!/:1.8.6] at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) >[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:10>4) [eureka-client-1.8.6.jar!/:1.8.6] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) >[na:1.8.0_151] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201>(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Schedu>ledThreadPoolExecutor.java:293) [na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) >[na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) >[na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151] at >java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~>[na:1.8.0_151] at >java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:>206) ~[na:1.8.0_151] at >java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~>[na:1.8.0_151] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~>[na:1.8.0_151] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_151] at >org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory>.java:121) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(Defaul>tClientConnectionOperator.java:180) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~>[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdap>ter.java:134) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDir>ector.java:610) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirect>or.java:445) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.jav>a:835) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.jav>a:118) ~[httpclient-4.5.5.jar!/:4.5.5] at >org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.jav>a:56) ~[httpclient-4.5.5.jar!/:4.5.5] at >com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4>Handler.java:173) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1] ... 29 common frames omitted
2018-04-11 15:38:20.140 WARN 6 --- [nfoReplicator-0] >c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with >message: java.net.ConnectException: Connection refused (Connection refused) 2018-04-11 15:38:20.140 WARN 6 --- [nfoReplicator-0] >com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/gateway - >registration failed Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute >request on any known server at >com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.exec>ute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.exec>ute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.8.6.jar!/:1.8.6] at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) >~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:10>4) [eureka-client-1.8.6.jar!/:1.8.6] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) >[na:1.8.0_151] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201>(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Schedu>ledThreadPoolExecutor.java:293) [na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) >[na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) >[na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
2018-04-11 15:38:20.141 WARN 6 --- [nfoReplicator-0] >c.n.discovery.InstanceInfoReplicator : There was a problem with the >instance info replicator
com.netflix.discovery.shared.transport.TransportException: Cannot execute >request on any known server at >com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.exec>ute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.ex>ecute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.exec>ute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.regi>ster(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.8.6.jar!/:1.8.6] at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) >~[eureka-client-1.8.6.jar!/:1.8.6] at >com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:10>4) ~[eureka-client-1.8.6.jar!/:1.8.6] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) >[na:1.8.0_151] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201>(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151] at >java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Schedu>ledThreadPoolExecutor.java:293) [na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) >[na:1.8.0_151] at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) >[na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
2018-04-11 15:38:50.043 ERROR 6 --- [tbeatExecutor-0] >c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error