Applications not registering to eureka when using docker-compose

后端 未结 2 1848
無奈伤痛
無奈伤痛 2021-01-22 10:53

I took this example https://github.com/paulc4/microservices-demo and I created 3 docker images from it, with the following Dockerfiles:

springdocker-registration:

<
相关标签:
2条回答
  • 2021-01-22 11:23

    For those who are working with docker-compose and if in your services yml file you have the following:

    eureka:
      client:
        serviceUrl:
          # Will get overridden in docker-compose
          defaultZone: http://localhost:1111/eureka
    

    You can override this in your docker-compose file like below while running docker-compose up

    version: "3.3"
    services:
    
     # Other services registered above
    
     web:
      image: springdocker-web
      environment: 
       # Important for clients to register with eureka
       - eureka.client.serviceUrl.defaultZone=http://registration:8761/eureka/
      ports:
       - "3333:3333"
      depends_on:
       - registration
       - accounts
      links:
       - registration
    

    Tested on Docker version 19.03.8

    0 讨论(0)
  • 2021-01-22 11:27

    Since its running in docker, don't use localhost. Docker compose lets you refer to container names.

    eureka:
      client:
        serviceUrl:
          defaultZone: http://registration:1111/eureka
    

    Side note: defaultZone must be exact, I spent 2 days wondering why it wouldn't work since intellij auto completes to do default-zone which wont work.

    0 讨论(0)
提交回复
热议问题