1

I have a Spring Boot app with the following config:

spring:
  thymeleaf:
    cache: false
  cloud:
    consul:
      host: consul
      port: 8500
      discovery:
        prefer-ip-address: true
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}

that I want to run with docker-compose(Docker 1.11.2, docker-compose 1.7.1):

consul:
  image: progrium/consul:latest
  container_name: consul
  hostname: consulhost
  ports:
    - "8400:8400"
    - "8500:8500"
    - "8600:53"
  command: "-server -bootstrap-expect 1 -ui-dir /ui"

collector-server:
  container_name: collector-server
  image: io.thesis/collector-server
  ports:
    - "9090:9090"
  links:
    - consul:consul

Unfortunately that does not work, I get: com.ecwid.consul.transport.TransportException: java.net.ConnectException: Connection refused.

I have absolutely no idea why it can't connect to Consul, because I can connect to other systems , e.g. rabbitmq in other applications exactly this way.

Thank you for any ideas!

Markus Lamm
  • 391
  • 1
  • 4
  • 15

1 Answers1

1

If you're trying to connect immediately when the container starts it's possible that consul is not ready to receive connections yet.

You need to write an entrypoint script to wait for the connection to be available, or even just retry the connection a few times. See https://docs.docker.com/compose/startup-order/ for more information.

dnephin
  • 25,944
  • 9
  • 55
  • 45
  • Thanks, I'll try...But I'm still wondering, because I never had to do that with rabbitmq, mysql, etc. Consul is starting very fast and the logs show that it's up before my spring application context is loading. – Markus Lamm Jul 27 '16 at 16:49
  • It works with docker-compose v2-format and depends_on. Thanks a lot! – Markus Lamm Jul 29 '16 at 09:23