This is a similar issue but the solution on this thread doesn't work for me. There is only one eureka instance per replica and other zones from that replica are not reachable.

Here is my sample project

I'm using swarm with two nodes on separate machines.

application.yml:

server:
  port: 8761

eureka:
  instance:
    hostname: ${HOSTNAME}
    appname: discovery
    prefer-ip-address: true
  client:
    register-with-eureka: true
    fetch-registry: true

spring:
  cloud:
    inetutils:
      ignoredInterfaces:
      - docker
      - eth.*
      - lo
      preferredNetworks:
      - 10.0

---
spring:
  profiles: peer1
eureka:
  client:
    service-url:
      defaultZone: http://${HOSTNAME}:8761/eureka/,http://${HOSTNAME}:8762/eureka/,http://${HOSTNAME}:8763/eureka/

---
spring:
  profiles: peer2
eureka:
  client:
    service-url:
      defaultZone: http://${HOSTNAME}:8761/eureka/,http://${HOSTNAME}:8762/eureka/,http://${HOSTNAME}:8763/eureka/

---
spring:
  profiles: peer3
eureka:
  client:
    service-url:
      defaultZone: http://${HOSTNAME}:8761/eureka/,http://${HOSTNAME}:8762/eureka/,http://${HOSTNAME}:8763/eureka/

docker-compose.yml:

version: '3'
services:
  eureka1:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8761:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery1

  eureka2:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8762:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery2

  eureka3:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8763:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery3

networks:
  springcloud-overlay:
    external:
      name: springcloud-overlay

deploy on swarm:

docker network create -d overlay springcloud-overlay
docker stack deploy -c docker-compose.yml discovery

Result: screen shot 2019-02-02 at 10 48 15 pm screen shot 2019-02-02 at 10 48 07 pm

I think I should change defaultZone to something like this but I don't know how to detect their IP:

defaultZone:
   http://10.0.8.1:8761, http://10.0.8.2:8761, http://10.0.8.3:8761

(assume that 10.0.8.1 is for the first instance, 10.0.8.2 for the second ...)

Note: I also disabled the firewall using ufw disable command.

Comment From: orias407

@SaeedMasoumi

When you have more than 2 Eureka instances configuration of appliction.yml should be something similar to below. Try changing your application.yml with below settings.

eureka:
  client:
    serviceUrl:
      defaultZone: http://${eureka1_HOSTNAME}:8761/eureka/,http://${eureka2_HOSTNAME}:8762/eureka/,http://${eureka3_HOSTNAME}:8763/eureka/

---
spring:
  profiles: eureka1
eureka:
  instance:
    hostname: eureka1_HOSTNAME

---
spring:
  profiles: eureka2
eureka:
  instance:
    hostname: eureka2_HOSTNAME

---
spring:
  profiles: eureka3
eureka:
  instance:
    hostname: eureka3_HOSTNAME

Comment From: SaeedMasoumi

These solutions didn't work for me unless I added 3 network aliases in each docker service and reference them in my defaultZone to find eureka servers.

docker-compose.yml

version: '3'
services:
  eureka1:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8761:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery1
    network:
      springcloud-overlay:
        - eureka1
        - eureka2
        - eureka3

  eureka2:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8762:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery2
    network:
      springcloud-overlay:
        - eureka1
        - eureka2
        - eureka3

  eureka3:
    image: 127.0.0.1:5000/discovery:1.0.0
    ports:
    - "8763:8761"
    environment:
    - SPRING_PROFILES_ACTIVE=discovery3
    network:
      springcloud-overlay:
        - eureka1
        - eureka2
        - eureka3

networks:
  springcloud-overlay:
    external:
      name: springcloud-overlay

application.yml

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka1:8761/eureka/,http://eureka2:8762/eureka/,http://eureka3:8763/eureka/

It works fine but I found timeout issues with Zuul, So finally I decided to remove Eureka and use docker itself as a discovery service.

Comment From: ecornely

In the end, have you a sample project that work fine? I'm facing the same issue and tried having aliases and reference each eureka by its hostname but still having the unavailable replicas...