У меня есть 2 моих пользовательских сервиса и один сервис как gateway-zuul, затем я запускаю эти сервисы без докера - все в порядке. Когда я пытаюсь создать композицию, я получаю странную ошибку Forwarding -> Connection отказано в исключении
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
gateway | at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:409) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
gateway | at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:328) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
gateway | at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:232) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
gateway | ... 63 common frames omitted
gateway | Caused by: java.net.ConnectException: Connection refused (Connection refused)
gateway | at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212]
gateway | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]
gateway | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212]
gateway | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212]
gateway | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212]
gateway | at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212]
gateway | at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ~[httpclient-4.5.8.jar!/:4.5.8]
gateway | ... 73 common frames omitted
Почему zuul пытается перенаправить мой запрос на localhost , а не на http://service1:8082?
Затем я захожу в контейнер шлюза и пингую service2 по имени хоста - все работает отлично! Контейнеры связаны, все в порядке
version: '3'
services:
gateway:
hostname: "gateway"
container_name: "gateway"
image: 'bla bla'
env_file:
- "./gateway/config.env"
ports:
- 8080:8080
networks:
- front-network
- back-network
service1:
hostname: "service1"
container_name: "service1"
image: 'bla bla'
env_file:
- "./service1/config.env"
ports:
- 8082:8080
depends_on:
- gateway
networks:
- back-network
service2:
hostname: "service2"
env_file:
- "./service2/config.env"
container_name: "service2"
image: 'bla bla'
ports:
- 8081:8080
depends_on:
- gateway
- service1
networks:
- front-network
networks:
front-network: {}
back-network: {}
Здесь мои zuul conifgs
zuul:
routes:
service2:
path: /bla bla/**
url: http://serivce2:8081
service1:
path: /bla bla/**
url: http://service1:8082
Я ожидаю, что zuul будет направлять запросы как без докера: (