Wiki: Failed to connect to MongoDB instance with docker-compose

Created on 19 Oct 2017  路  8Comments  路  Source: Requarks/wiki

Actually the Wiki.js is not accessible due to a connection issues with the mongodb.
I am using the unchanged docker-compose.yml file.

This is the log:

2017-10-19T09:38:53.683Z - info: [SERVER] Search index flushed and ready.
2017-10-19T09:38:53.741Z - info: [SERVER] Git repository is OK.
2017-10-19T09:38:53.780Z - info: [AGENT] Background Agent is initializing...
2017-10-19T09:38:54.378Z - info: [AGENT] Checking Git repository...
2017-10-19T09:38:55.019Z - error: [AGENT] Failed to connect to MongoDB instance.
Unhandled rejection MongoError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/var/wiki/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:115:13)
    at Pool.emit (events.js:210:7)
    at Connection.<anonymous> (/var/wiki/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Object.onceWrapper (events.js:318:30)
    at emitTwo (events.js:125:13)
    at Connection.emit (events.js:213:7)
    at Socket.<anonymous> (/var/wiki/node_modules/mongodb-core/lib/connection/connection.js:187:49)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
2017-10-19T09:38:55.078Z - info: [AGENT] Git repository is OK.

This is the file:

version: '3'
services:
  wikidb:
    image: mongo
    expose:
      - '27017'
    command: '--smallfiles --logpath=/dev/null'
    volumes:
      - ./data/mongo:/data/db
  wikijs:
    image: 'requarks/wiki:latest'
    links:
      - wikidb
    ports:
      - '80:3000'
    environment:
      WIKI_ADMIN_EMAIL: [email protected]
    volumes:
      - ./config.yml:/var/wiki/config.yml

Would be happy if someone could help.

Thank you im advance.
Paul

Most helpful comment

Just fought 2h this morning on the same issue. You need to change the db parameter in the config.yml file to mongodb://wikidb:27017/wiki (ie, wikidb, the name of the docker-compose service, instead of 127.0.0.1)

All 8 comments

Just fought 2h this morning on the same issue. You need to change the db parameter in the config.yml file to mongodb://wikidb:27017/wiki (ie, wikidb, the name of the docker-compose service, instead of 127.0.0.1)

That was it.
Thank you!

281 I think the docs should warn users about this

Just fought 2h this morning on the same issue. You need to change the db parameter in the config.yml file to mongodb://wikidb:27017/wiki (ie, wikidb, the name of the docker-compose service, instead of 127.0.0.1)

  • Thanks a lot, I spent 3 days

I still have this error. My service name in docker.yaml file is "mongo". Hence the url string express is "mongodb://mongo:27017/Puzzle". But I get the error as
MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongo mongo:27017]

When I run docker-compose up I see below mongoose connection error in the log.

Error: getaddrinfo ENOTFOUND mongod
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {}
}

Then a few lines later I see the mongo container log that it is "waiting for connections on port 27017". I tried use a depends_on in my docker-compose.yml

How do I make it so my API container does not prematurely connect to my Mongo container before it is ready to accept connections?

@CGTB Please keep the discussion relevant to the topic at hand and reply in English.

Enjoy your ban.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

den1622 picture den1622  路  3Comments

thinkh picture thinkh  路  4Comments

gruesomehit picture gruesomehit  路  4Comments

D3mon86 picture D3mon86  路  4Comments

sleepadru picture sleepadru  路  4Comments