首次连接时无法连接到服务器 [mongo:27017] [错误:连接 ECONNREFUSED 127.0.0.1:27017

时间:2021-01-04 17:22:04

标签: node.js mongodb docker centos8 podman

我在使用 mongoDB 连接到容器时遇到问题

我的 DockerFile:

FROM node:14.15.1
RUN npm install nodemon -g
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY --chown=node:node . .
USER node
EXPOSE 3052
CMD ["nodemon"]

docker-compose.yml

version: "3.9"
services:
  mongo:
    image: 'mongo'
    volumes:
      - "/opt/data/db:/data/db"
  web:
    build: .
    ports:
      - 3052:3030
    depends_on:
      - mongo

当我运行命令“podman-compose up”时,我收到以下日志

[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src`
(node:20) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use `node --trace-deprecation ...` to show where the warning was created)
info: Feathers application started on http://localhost:3030

failed to connect to server [mongo:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

我可以怎样解决这个问题?

解决

docker-compose.yml 中的 mongo 数量不正确。删除它后 mongo 它工作。 /data/db 权限被拒绝的问题。

0 个答案:

没有答案