在Docker中无法连接Consul和Spring Boot应用程序 [英] Cannot link Consul and Spring Boot app in Docker

查看:3029
本文介绍了在Docker中无法连接Consul和Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下配置的Spring Boot应用程序:

  spring:
百里香:
缓存:false
云:
consul:
主机:consul
端口:8500
发现:
prefer-ip-address:true
instanceId:$ {spring.application.name}:$ {spring.application.instance_id:$ {random.value}}

我想用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
命令:-server -bootstrap-expect 1 -ui-dir / ui

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

不幸的是,这不工作,我得到:com.ecwid.consul.transport.TransportException:java.net.ConnectException:Connection refused。



我绝对不知道为什么它不能连接到领事,因为我可以连接到其他系统,例如在其他应用程序中的rabbitmq正是这样的。



谢谢任何想法!

解决方案>

如果您尝试在容器启动时立即连接,那么领事可能尚未准备好接收连接。



您需要编写一个entrypoint脚本来等待连接可用,甚至只是重试连接几次。请参见 https://docs.docker.com/compose/startup-order/ 更多信息。


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!

解决方案

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.

这篇关于在Docker中无法连接Consul和Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆