首次连接时无法连接到服务器

时间:2020-03-26 17:30:32

标签: node.js mongodb

我的代码中出现此错误

mongodb-c | Error parsing command line: unrecognised option '--smallfiles'
mongodb-c | try 'mongod --help' for more information
mongodb-c exited with code 2
api_1     | 
api_1     | > agte-api@1.0.0 start /app
api_1     | > nodemon index.js --watch
api_1     | 
api_1     | [nodemon] 1.19.4
api_1     | [nodemon] to restart at any time, enter `rs`
api_1     | [nodemon] watching dir(s): *.*
api_1     | [nodemon] watching extensions: js,mjs,json
api_1     | [nodemon] starting `node index.js`
api_1     | (node:30) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-client
api_1     | Server is running on http://localhost:3000 or http://127.0.0.1:3000
api_1     | Mongoose connection error: MongoError: failed to connect to server [db:27017] on first connect [Error: getaddrinfo ENOTFOUND db
api_1     |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:64:26) {
api_1     |   name: 'MongoError',
api_1     |   message: 'getaddrinfo ENOTFOUND db'
api_1     | }]
api_1     | [nodemon] app crashed - waiting for file changes before starting...

代码:

version: '2'
services:
  db:
    image: mongo
    container_name: 'mongodb-c'
    ports:
      - "27017:27017"
    command:
      - --smallfiles
    # environment:
    #   - MONGO_INITDB_ROOT_USERNAME=superuser
    #   - MONGO_INITDB_ROOT_PASSWORD=admin
    #   - MONGO_INITDB_DATEBASE=admin
    volumes:
    - db:/data/db
  api:
    build: .
    command: npm start
    ports:
      - 3000:3000
      - 5858:5858
    volumes:
      - '/api'
    depends_on:
      - db
    links:
      - db
    environment:
      PORT: 3000
volumes:
  db:

0 个答案:

没有答案