我是领事新手。我开发了一个可以注册自己的spring boot应用程序,我可以从控制台的其他应用程序中发现它。但是如果我尝试将这个应用程序容器化,它就无法连接到控制台:我在docker容器中运行console:
docker run -p 8500:8500 consul:latest
控制台启动,我可以看到网页:http://localhost:8500
然后我创建我的应用程序的docker镜像并运行它
docker build . -t app
docker run -p 8888:8888 app
它无法连接到控制台,我收到以下错误,
main] o.s.c.c.c.ConsulPropertySourceLocator : Fail fast is set and there was an error reading configuration from consul.
我在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}
陷入类似的问题,这里的问题可能是容器问题。我通过确保容器在同一网络下运行来解决它。另外,请确保在上面的配置中使用容器名称而不是“localhost”。例如:
弹簧:
cloud:
consul:
host: consul //container name
port: 8500