我正在尝试在我的 OS X 开发机器上的 docker 容器中部署我的 JHipster 微服务和注册表。
我使用 JHipster 开箱即用的默认 docker-compose 配置部署注册表:
version: '2'
services:
jhipster-registry:
image: jhipster/jhipster-registry:v3.1.0
volumes:
- ./central-server-config:/central-config
# When run with the "dev" Spring profile, the JHipster Registry will
# read the config from the local filesystem (central-server-config directory)
# When run with the "prod" Spring profile, it will read the configuration from a Git repository
# See https://jhipster.github.io/microservices-architecture/#registry_app_configuration
environment:
- SPRING_PROFILES_ACTIVE=dev,native
- SECURITY_USER_PASSWORD=admin
- SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/localhost-config/
# - GIT_URI=https://github.com/jhipster/jhipster-registry/
# - GIT_SEARCH_PATHS=central-config
ports:
- 8761:8761
但是,当我使用 部署我的微服务docker run
时,会发生以下两种情况之一:
如果我发布了我想让微服务可用的端口,-p 8080:8080
以便我可以通过浏览器访问它,我可以访问它,但微服务找不到注册表。
Could not locate PropertySource: I/O error on GET request for "http://jhipster-registry:8761/config/clientaggregator/dev,twilio": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
同时,我可以查看注册表服务正常的页面。
我可以通过在启动微服务时添加“--network=host”来解决这个问题。但是,当我这样做时,这显然会覆盖本机到主机的端口映射,并且无法从浏览器访问微服务。
更奇怪的是,大约一周前,我使用了完全相同的配置,效果很好。
如果我在 docker 容器之外运行我的应用程序,它会很好地连接到注册表。如果我创建一个不同的容器,或者连接到微服务容器并通过 curl 访问配置 url,我会收到响应。