我正在尝试将我的JHipster微服务和注册表部署在我的OS开发机器上的docker容器中。
我或多或少使用了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,我会得到一个响应。
发布于 2017-09-05 23:08:57
你的应用程序正在尝试使用名称jhipster-registry作为主机名来查找注册表。要做到这一点,您需要将您的注册表和应用程序添加到docker网络。
首先使用以下命令创建网络:
docker network create my-network通过为容器指定名称并将其添加到network create来更新撰写文件:
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
networks:
- my-network
container_name: jhipster-registry
networks:
my-network:
external: true在运行应用程序时,请指定网络:
docker run --network=my-network ...现在,您的应用程序可以使用jhipster-registry作为主机名与注册表通信。
https://stackoverflow.com/questions/46058052
复制相似问题