[英]Docker compose cross containers communication
I'm a very beginner in docker world, and I'm not able to make two containers communicate using docker compose. 我是docker世界中的一个初学者,我无法使用docker compose使两个容器通信。 I have two containers: 我有两个容器:
All work fine without docker !! 没有泊坞窗,一切正常! And now with docker-compose, the gateway is not able to find the Eureka server URL. 现在使用docker-compose,网关无法找到Eureka服务器URL。
docker-compose.yml file: docker-compose.yml文件:
version: '3.5'
services:
gateway:
build:
context: ../robots-store-gateway
dockerfile: Dockerfile
image: robots-store-gateway
ports:
- 8000:8000
networks:
- robots-net
serviceregistry:
build:
context: ../robots-sotre-serviceregistry
image: robots-sotre-serviceregistry
ports:
- 8761:8761
networks:
- robots-net
networks:
robots-net:
name: custom_network
driver: bridge
The application.yml file of the gateway is: 网关的application.yml文件为:
eureka:
client:
service-url:
default-zone: http://serviceregistry:8761/eureka/
I receive this exception: 我收到此异常:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException:连接被拒绝(连接被拒绝)
I tried different ways to configure the Eureka client but no way !! 我尝试了其他方法来配置Eureka客户端,但是没有办法! it doesn't work. 它不起作用。 Thanks in advance. 提前致谢。
I don't exactly why !!! 我也不是为什么! But finally, this works for me: 但最后,这对我有用:
version: '3.5'
services:
gateway:
container_name: gateway
build:
context: ../robots-store-gateway
dockerfile: Dockerfile
image: robots-store-gateway
ports:
- 8000:8000
hostname: gateway
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
serviceregistry:
container_name: serviceregistry
build:
context: ../robots-sotre-serviceregistry
image: robots-sotre-serviceregistry
ports:
- 8761:8761
hostname: serviceregistry
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.