对于 JHipster 微服务架构,我在 docker 容器中运行名为 AuthServer 的 UAA 服务器,在另一个容器中运行 Jhipster 注册表。
docker 容器在相同的用户网桥网络配置中运行。
由于注册表不在同一个容器中,我将我的 UAA 服务器配置为连接到我的 application.yml 文件中的 jhipster-registry 机器
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://admin:${jhipster.registry.password}@jhipster-registry:8761/eureka/
同样,我在 bootstrap.yml 文件中使用了它:
spring:
cloud:
config:
fail-fast: true
retry:
initial-interval: 1000
max-interval: 2000
max-attempts: 100
uri: http://admin:${jhipster.registry.password}@jhipster-registry:8761/config
最后在我的 docker-compose 文件中,我还使用了
version: '3.3'
services:
authserver-app:
image: authserver
environment:
- _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
- SPRING_DATASOURCE_URL=jdbc:postgresql://authserver-postgresql:5432/AuthServer
- JHIPSTER_SLEEP=10 # gives time for the JHipster Registry to boot before the application
但是当我启动应用程序 AuthServer 时,它会继续尝试连接到 localhost
authserver-app_1 | 2019-01-04 18:07:39.134 DEBUG 1 --- [ restartedMain] c.n.d.s.r.aws.ConfigClusterResolver : Config resolved to [AwsEndpoint{ serviceUrl='http://admin:admin@localhost:8761/eureka/', region='us-east-1', zone='defaultZone'}]
authserver-app_1 | 2019-01-04 18:07:39.141 DEBUG 1 --- [ restartedMain] c.n.d.s.r.a.ZoneAffinityClusterResolver : Local zone=defaultZone; resolved to: [AwsEndpoint{ serviceUrl='http://admin:admin@localhost:8761/eureka/', region='us-east-1', zone='defaultZone'}]
这个关于 localhost 的配置来自哪里,我该如何修复它?