Reputation: 1431
I try to execute Spring Boot jar file with Consul on Windows 10. First I installed Consul on Windows 10. Then I execute Spring Boot jar file. For your information, below is the application.properties.
spring.cloud.consul.host=192.168.200.51
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.healthCheckInterval=300s
spring.cloud.consul.config.enabled=true
spring.application.name = blog-app-service
And http://localhost:8500/ui
on the web browser can discover the service successfully. But I dockerize the Spring Boot project. Running the Docker container is successful. But connection to Consul failed. The exception is as below:
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8500 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:140) ~[httpclient-4.5.8.jar!/:4.5.8]
at com.ecwid.consul.transport.AbstractHttpTransport.executeRequest(AbstractHttpTransport.java:61) ~[consul-api-1.4.1.jar!/:na]
Before dockerizing the Spring Boot jar, my project is connected with Consul without errors. But after dockerizing, the connection is refused. Did I miss any procedure when dockerizing?
Upvotes: 1
Views: 12651
Reputation: 1622
Use host.docker.internal as a host of your machine from docker.
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows.
More info: https://docs.docker.com/docker-for-windows/networking/#known-limitations-use-cases-and-workarounds
Upvotes: 2