I am on CentOS-8 and have a couple of spring-boot services: demo-client calls demo-server over HTTP through spring RestTemplate. This works fine without Docker container.
But when I deploy them as docker-compose with default network, demo-client is not able to call demo-server. I tried with service-name and also with ip-address of the container but same error in both cases:
demo-client_1 | 2020-02-29 10:23:55.165 ERROR 1 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: **I/O error on GET request for "http://172.24.0.2:8081/hello": Host is unreachable (Host unreachable);** nested exception is java.net.NoRouteToHostException: Host is unreachable (Host unreachable)] with root cause demo-client_1 | demo-client_1 | java.net.NoRouteToHostException: Host is unreachable (Host unreachable) demo-client_1 | at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212] demo-client_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]*
Docker compose file :
docker-compose.yml:
version: '3'
services:
demo-client:
build: ./demo-client
ports:
- "8082:8082"
depends_on:
- demo-server
demo-server:
build: ./demo-server
ports:
- "8081:8081"
I tried following firewall related actions as suggested in some of the earlier posts:
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --reload
service firewalld restart*
None of this worked. What I thought to be a straight forward thing turned out to be more complex.
2
Answers
The issue is with Centos-8 and The same code worked fine with CentOS-7. so, for now I moved back to Centos-7. CentOS-8 introduced Podman as official container tool instead of Docker
In my case firewall blocking elastic port from the container. I stopped the firewall and restarted the application it worked.