node.js - 错误 : getaddrinfo ENOTFOUND with docker-c

我正在构建一个 React,Node 应用程序并且我正在使用 docker-compose 我的 docker compose 定义如下所示:

version: "3"
services:
  frontend:
    stdin_open: true
    container_name: firestore_manager
    build:
      context: ./client/firestore-app
      dockerfile: DockerFile
    image: rasilvap/firestore_manager
    ports:
      - "3000:3000"
    volumes:
      - ./client/firestore-app:/app
    environment:
      - BACKEND_HOST=backend
      - BACKEND_PORT=8081
    depends_on:
      - backend
  backend:
    container_name: firestore_manager_server
    build:
      context: ./server
      dockerfile: Dockerfile
    image: rasilvap/firestore_manager_server
    ports:
      - "8081:8081"
    volumes:
      - ./server:/app
    environment:
      - BACKEND_HOST=backend
      - BACKEND_PORT=8081

我正在尝试使用 docker-compose 文件中定义的 backend 前缀访问 NodeJs 后端端点,但我收到了一个错误:getaddrinfo ENOTFOUND firestore_manager_server,使用容器名称也会发生同样的情况:firestore_manager_server

如您在下一个网址中所见:

firestore_manager_server:8081/firestore?collection=test&field=nombre&value=xxxx
backend:8081/firestore?collection=test&field=nombre&value=xxxx

我在使用 localhost 时没有任何问题。

接下来是docker ps命令的结果:

有什么想法吗?

最佳答案

我相信你的网址应该是

前端:8081/firestore?collection=test&field=nombre&value=xxxx

代替

firestore_manager_server:8081/firestore?collection=test&field=nombre&value=xxxx

关于node.js - 错误 : getaddrinfo ENOTFOUND with docker-compose server definition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62630645/

相关文章:

asp.net - 如何为网络浏览器的用户获取 AD 属性

swift - 达到最大时间戳计数,不会记录更多事件 Xcode

amazon-web-services - server.servlet.context-path

google-chrome - 报告 api : Is there a way to debug w

flutter - 如何解决 PlatformException (PlatformExceptio

php - 如何在 Ubuntu 16.04 中安装 php-curl

python - 如何在 Tkinter 窗口上使用 for 循环创建多个框架?

r - 控制 geom_line() 图表中的日期(x 轴)间隔

python - 如何从不同的文件调用方法而不在python中导入它

microsoft-graph-api - 在新的限制下使用 Microsoft Graph API