我有两个 docker compose 文件。
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'
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'
...
在我的本地机器上:
在我的 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 容器?
感谢您的观看!