software.developer
software.developer

Reputation: 308

Spring boot docker container can not connect consul

I am new to consul. I have developed a spring boot application which can register itself and I can discover it from other application from console. But if I try to containerize this application, it fails to connect to console: I run console in docker container:

docker run -p 8500:8500 consul:latest

Console starts and I can see the webpage: http://localhost:8500

Then I create a docker image of my app and run that by

docker build . -t app
docker run -p 8888:8888 app

It fails to connect to console, and I get following error,

main] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.

I have following in bootstrap.yml,

 spring:
      application:
        name: app
      cloud:
        consul:
          host: localhost
          port: 8500
          discovery:
            preferIpAddress: true
            healthCheckPath: /health
            healthCheckInterval: 15s
            instanceId: ${spring.application.name}:${random.value}

Upvotes: 1

Views: 1544

Answers (1)

Mayank Gupta
Mayank Gupta

Reputation: 2177

Got into a similar issue, the problem here could be with containers. I solved it by making sure that the containers run under the same network. Also, make sure to use container name instead of "localhost" in the above configuration. Eg:

spring:

cloud:

  consul:

    host: consul //container name

    port: 8500

Upvotes: 2

Related Questions