【问题标题】:ECONNREFUSED with NodeJS and InfluxDb on docker在 docker 上使用 NodeJS 和 InfluxDb ECONNREFUSED
【发布时间】:2022-10-17 17:46:02
【问题描述】:

我在连接到在 docker 中运行的 InfluxDB 实例时遇到问题。

我使用以下命令提取 InfluxDB 映像:

docker pull influxdb:2.4.0 

并使用 Docker Desktop 在本地运行,一切正常,以下是我的日志:

但现在我想连接到这个实例,如下所示:

export const influx = new Influx.InfluxDB({
  host: 'localhost',
  port: 8086,
  database: 'ocean_tides',
  schema: [
    {
      measurement: 'tide',
      fields: { height: Influx.FieldType.FLOAT },
      tags: ['unit', 'location']
    }
  ]
});

当我尝试像这样测试连接时:

await influx.getDatabaseNames()

服务器向我扔了这个:

connect ECONNREFUSED 127.0.0.1:8086

有人可以告诉我我做错了什么吗?

谢谢你的帮助!

【问题讨论】:

    标签: node.js typescript docker nestjs influxdb


    【解决方案1】:

    不能使用 127.0.0.1 或 localhost 连接到容器外的服务!

    请将127.0.0.1 / localhost 替换为host.docker.internal 以便连接到主机。

    【讨论】:

      猜你喜欢
      • 2020-02-03
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 2016-09-01
      • 2020-04-09
      • 2019-02-19
      • 2021-08-12
      相关资源
      最近更新 更多