作为Docker容器运行时,Java Spring不会与Consul通信

我正试图解决我认为是运行微服务的常见用例。 在这种情况下,我正在用一个spring的云应用程序testing领事。 我试图用两种不同的方式来testing领事。 其中第一个运行在Docker容器中,另一个运行在Docker主机上。 然后,我试图启动一个spring的云容器,将与任何一个领事的例子。

当Spring云应用程序作为docker容器运行时,我无法使Spring云应用程序与领事谈话。 当Spring云应用程序以主机联网模式运行时,它可以parsinglocalhost端口,但是如果我希望运行多个图像实例,这不是一个可接受的解决scheme。

下面显示了将两个服务作为容器运行时,我的泊坞窗撰写文件的示例。 在这里,我试图通过环境variables来设置春季云中的领队uri,但却无法使用各种configuration使其工作。 如果任何人都可以指出这些function一起工作的例子,那将是非常有用的。

consul1: image: progrium/consul ports: - "8400:8400" - "8500:8500" - "8600:53/udp" - "8600:53/tcp" environment: GOMAXPROCS: 100 entrypoint: "/bin/consul" hostname: consul command: agent -log-level=debug -server -config-dir=/config -bootstrap -ui-dir /ui simpletest: build: simpletest hostname: simpletest environment: JAVA_OPTS: "-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n -Dspring.cloud.consul.host=consul1" ports: - 39041:7051 - 39052:7055 # d2fdockerroot_consul1_1 consul # links: # - consul1 

这里有一个啤酒厂系统的例子 – https://github.com/spring-cloud-samples/brewery 。 其中一个文件是CONSUL的docker-compose文件。

https://github.com/spring-cloud-samples/brewery/blob/master/docker-compose-CONSUL.yml

查看代码库中的所有application-consul.yaml文件,了解如何设置Spring Boot应用程序与领事交谈。

例如: https : //github.com/spring-cloud-samples/brewery/blob/master/aggregating/src/main/resources/application-consul.yaml

如果有任何问题,请写在这里或去spring-cloud gitter https://gitter.im/spring-cloud/spring-cloud

我有同样的问题:连接到我的领事容器是不够的。 但是,下面这个对我来说是这样的:正如这里所说的,相应的consul主机和端口configuration需要放在bootstrap.yml ,而不是application.yml

 spring: cloud: consul: host: consul port: 8500 

与相应docker-compose.yml

 version: "2.0" services: consul: image: consul:latest ports: - "8500:8500" my-service: build: path/to/dockerfile depends_on: - consul links: - consul:consul