title: Eureka Client Registration Failed in Docker compose: Failing to register as client - but eureka server & client is individually up & running
body: <p>I have a spring boot application for <strong>Eureka Server</strong>:</p>
  <p><strong>application.yml (Eureka Server)</strong></p>
  <pre><code>server:
    port: 8761
  
  spring:
    application:
      name: eureka
  
  eureka:
    client:
      register-with-eureka: false
      fetch-registry: false
  </code></pre>
  <p>I have a eureka client - say microservice2</p>
  <p><strong>application.yml (Eureka Client - microservice2)</strong></p>
  <pre><code>spring:
    application:
      name: second-feign-client
  
  server:
    port: 8082
  
  eureka:
    client:
      service-url:
        defaultZone: http://localhost:8761/eureka
  </code></pre>
  <p><strong>Dockerfile: (same for both eureka-server app &amp; microservice2 app)</strong></p>
  <pre><code>FROM openjdk:8-jdk-alpine
  ARG JAR_FILE=target/*.jar
  COPY ${JAR_FILE} app.jar
  ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;/app.jar&quot;]
  </code></pre>
  <p>locally, Eureka client, <strong>microservice2</strong>, registering with Eureka Server perfectly. Both are spring boot applications. I have dockerized both applications, &amp; pushed to docker hub. I am trying to run these two applications in docker-compose, but the eureka client is failing to register in eureka server using docker-compose.</p>
  <p>I am getting this error:</p>
  <pre><code>microservice2_1  | 2020-09-07 13:56:36.149 ERROR 1 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : D
  iscoveryClient_SECOND-FEIGN-CLIENT/379b7c698e87:second-feign-client:8082 - was unable to refresh its cache! status =
  Cannot execute request on any known server
  microservice2_1  |
  microservice2_1  | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known ser
  ver
  microservice2_1  |      at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(Retryab
  leEurekaHttpClient.java:112) ~[eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications
  (EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(Eurek
  aHttpClientDecorator.java:137) ~[eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(Session
  edEurekaHttpClient.java:77) ~[eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications
  (EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1097) [
  eureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:1011) [eureka-cli
  ent-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1533) [eureka-c
  lient-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1500) [e
  ureka-client-1.9.25.jar!/:1.9.25]
  microservice2_1  |      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_212]
  microservice2_1  |      at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_212]
  microservice2_1  |      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_
  212]
  microservice2_1  |      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_
  212]
  microservice2_1  |      at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
  microservice2_1  |
  eureka-server_1  | 2020-09-07 13:56:39.393  INFO 1 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : R
  unning the evict task with compensationTime 0ms
  </code></pre>
  <p><strong>I have gone through already discussed related question</strong> <a href="https://stackoverflow.com/questions/44667063/docker-and-eureka-with-spring-boot-failing-to-register-clients">docker-eureka-spring-boot</a> <strong>I have tried all these discussed options, but still not working.</strong></p>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: &quot;3.8&quot;
  services:
    eureka-server:
      image: dineshdontha67/eureka-server:latest
      ports:
      - &quot;8761:8761&quot;
      networks:
        - ms-network
    microservice2:
      image: dineshdontha67/microservice2:latest
      ports:
      - &quot;8082:8082&quot;
      networks:
        - ms-network
      depends_on:
        - eureka-server
      environment:
        server.port: 8082
        eureka.instance.hostname: localhost
        eureka.client.enabled: 'true'
  
  #EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://localhost:8761/eureka
  #    networks:
  #      - ms-network
  #    depends_on:
  #      - eureka-server
  #      server.port: 8082
  #      eureka.host: eureka-server
  #      eureka.client.enabled: 'true'
  #      eureka.instance.preferIpAddress: 'true'
  
  networks:
    ms-network:
      driver: bridge
  </code></pre>
  <p>Note: After docker-compose up, both the spring boot applications are running fine individually, but only registration is failing.</p>
  <pre><code>E:\eureka-server&gt;docker-compose ps
              Name                     Command         State           Ports
  -----------------------------------------------------------------------------------
  eureka-server_eureka-server_1   java -jar /app.jar   Up      0.0.0.0:8761-&gt;8761/tcp
  eureka-server_microservice2_1   java -jar /app.jar   Up      0.0.0.0:8082-&gt;8082/tcp
  </code></pre>
  <p><strong>Reference Repos:</strong></p>
  <p>microservices2 git repo (acts as eureka-client) : <a href="https://github.com/donthadineshkumar/spring-boot-microservice2.git" rel="nofollow noreferrer">microservices2</a></p>
  <p>eureka-server git repo(acts as eureka server): <a href="https://github.com/donthadineshkumar/spring-boot-eureka-server.git" rel="nofollow noreferrer">eureka-server</a></p>
  <p>Please help me on this. Thanks a ton!</p>