2017-09-05 69 views
0

我想在我的OS X开发机器上的Docker容器中部署JHipster微服务和注册表。Docker容器中的JHipster应用程序无法在主机网络上访问,无法与非主机网络上的其他容器通信

我使用更多或更少的默认泊坞窗,撰写配置JHipster提供开箱即用的部署注册表:

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”来解决这个问题。但是,当我这样做时,显然会覆盖本机到主机端口的映射,并且无法从浏览器访问微服务。

更奇怪的是,大约一个星期前,我使用完全相同的配置,工作正常。

enter image description here

如果我运行一个泊坞窗容器外我的应用程序,它连接到注册表的罚款。如果我创建一个不同的容器,或者连接到微服务容器并通过curl访问配置url,我会得到一个响应。

回答

-1

您的应用正在尝试使用名称jhipster-registry作为主机名来查找注册表。为了做到这一点,您需要将您的注册表和应用添加到码头网络中。

首先使用创建网络:

docker network create my-network 

更新撰写文件,通过给容器的名称,然后将其添加到网络创建:

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 ... 

现在您的应用程序可以使用0123与注册表进行通信作为主机名。

+0

我无法从我的浏览器访问容器。 – ThisIsNoZaku

+0

@ThisIsNoZaku你能提供docker ps的输出吗? – yamenk

+0

'fae11e00e397 clientaggregator“/ bin/sh -c'echo ...”6分钟前6分钟5701/udp,0.0.0.0:32769->8081/tcp wizardly_pasteur1' – ThisIsNoZaku

相关问题