Cloud config got Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} from Eureka server

Artem Vlasenko :

I'm trying to implement Discovery First Bootstrap way for my 4 micro-services. First is a config server that takes config from git, and second is an Eureka server. When i'm running docker-compose up my config server is not able to register with eureka. I've got:

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} Connection refused

My config server

 @EnableConfigServer
    @EnableEurekaClient
    @SpringBootApplication
    public class ConfigServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }

application.yml

   server:
  port: 8888
spring:
  cloud:
    config:
      server:
        encrypt.enabled: false
        git:
          uri: https://github.com/Artuwok/artbook-config-repo/
          searchPaths: userservice
          username: Artuwok
          password: Civilization1986
          timeout: 10
          force-pull: true

bootstrap.yml

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: true
      discovery.enabled: true

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://localhost:8761/eureka/

Eureca class

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

Eureka bootstrap.yml

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

docker-compose.yml with full config

version: '3'

services:

  configserver:
    image: configserver:1.0
    ports:
      - "8888:8888"
    depends_on:
      - eurekaserver
    restart: on-failure

  eurekaserver:
    image: eurekasvr:1.0
    ports:
      - "8761:8761"


  users_db:
    image: mysql:5.7
    container_name: users_db
    restart: always
    environment:
      - MYSQL_DATABASE=artbook
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
    volumes:
      - users_db:/var/lib/mysql
    ports:
      - "3306:3306"
    depends_on:
      - eurekaserver

  user-service:
    image: userservice:1.0
    ports:
      - "8080:8080"
    depends_on:
      - eurekaserver
      - configserver
    restart: on-failure
volumes:
  users_db:

So in the end i was able to start-up the services. Pay huge attention to URL on which you are discovering service. If you are using docker images you must use service name, not localhost in uri and urls's. My working config

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: false
      discovery.enabled: false
      uri: http://configserver:8888

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://eurekaserver:8761/eureka
Daria Pydorenko :

You config server and Eureka server both run in Docker. So they can connect with each other using their names in Docker, not localhost.

So Eureka service URL should be: http://eurekaserver:8761/.

And you should add the code below to your configserver configuration in docker-compose.yml:

links:
    - eurekaserver

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=150570&siteId=1