Docker:网关连接拒绝其他 Docker 容器/撰写文件(Angular -> Nestjs)

问题描述 投票:0回答:0

我有两个 docker compose 文件。

  1. Docker 为我的 Angular 通用应用程序撰写:
version: '3.8'
services:
  myproject:
    build:
      context: .
      dockerfile: ./apps/myproject/Dockerfile
      target: development-build
    command: yarn run dev:ssr
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - '4200:4200'
  1. Docker Compose 为我的 NestJs 服务
version: '3.8'
services:
  api:
    build:
      context: .
      dockerfile: ./apps/api/Dockerfile
      target: development-build
    command: npm run start:dev api
    env_file:
      - ./apps/api/.env
    depends_on:
      - rabbitmq
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - '3000:3000'
...

在我的本地机器上:

  • localhost:4200 可访问并显示角度应用程序
  • localhost:3000 可访问并且 api 端点工作

在我的 Angular 应用程序中,我使用我的代理 conf 代理所有对 localhost:3000 的 api 调用:

{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

无需 docker 即可完美运行。 但是当我在我的机器上运行两个 docker compose 文件时,我得到一个 ECONNREFUSED 错误:

[HPM] Proxy created: /api  -> http://localhost:3000
 | [HPM] Subscribed to http-proxy events: [ 'error', 'close' ]
 | ** Angular Universal Live Development Server is listening on http://localhost:4200, open your browser on http://localhost:4200 **
 | [HPM] POST /api/auth/local/login -> http://localhost:3000
 | [HPM] Error occurred while proxying request localhost:4200/api/auth/local/login to http://localhost:3000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

我缺少什么允许角度应用程序(节点服务器)通过端口 3000 到达另一个 docker 容器?

感谢您的观看!

angular docker docker-compose angular-universal
© www.soinside.com 2019 - 2024. All rights reserved.