将请求发送到另一个容器时docker中的连接被拒绝

时间:2018-11-06 04:11:44

标签: docker

我正在本地主机上的docker内部运行这两个程序。

当我从一个容器向另一个容器发送请求时,出现连接被拒绝错误。

一个运行在8000端口上,另一个运行在8001上。

我使用命令docker run -p 8000:8000 service1运行图像,反之亦然。

我正在尝试连接从8001开始在8000上运行的服务。

我收到如下错误:

connect ECONNREFUSED 0.0.0.0:8000

1 个答案:

答案 0 :(得分:0)

您需要以网络模式将Docker-Compose用作主机

 network_mode: "host"

检查样本Docker-compose文件:-

version: '2.1'

services:

#Governing microservices
  api-gateway:
   build: zuul-apigateway/
   depends_on:
    eureka-server:
     condition: service_healthy
   restart: always
   network_mode: "host"
   image: demo-zuul-service
   hostname: localhost
   ports:
    - 9085:9085
   healthcheck:
    test: "exit 0"

  eureka-server:
   build: eureka-server/
   restart: always
   network_mode: "host"
   image: demo-eureka-service
   hostname: localhost
   ports:
    - 9083:9083
   healthcheck:
    test: "exit 0"

现在这两个容器都可以相互通信,就像主机网络

引用:-

https://github.com/thoopalliamar/Juggler/blob/master/docker-compose.yml

这是13个微服务应用程序,可以相互通信。

相关问题