2017-09-05 67 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

相關問題