I am trying to deploy my JHipster microservices and registry in docker containers on my OS X development machine.
I deploy the registry using more or less the default docker-compose configuration JHipster provides out of the box:
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
When I deploy my microservices using docker run
, however, one of two things happens:
If I publish the port I want to make the microservice available on using -p 8080:8080
so I can access it through the browser, I can reach it but the microservice cannot find the registry.
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)
Meanwhile, I can view the pages the registry serves fine.
I can fix this by adding "--network=host" when starting the microservice. However, when I do that this apparently overrides the native-to-host port mapping and the microservice cannot be reached from the browser.
What's more bizarre is that about a week ago I was using the exact same configuration, which worked fine.
If I run my application outside of a docker container, it connects to the registry fine. If I create a different container, or connect to the microservice container and access the configuration url via curl, I get a response.
Your app is trying to locate the registry using the name
jhipster-registry
as a host name. To be able to do that, you need to have your registry and app added to a docker network.First create the network using:
Update the compose file by giving the container a name and adding it to the network create:
When running your application specify the network:
Now your application can communicate with the registry using
jhipster-registry
as a hostname.