Rocket.chat: ther is a docker's bug

Created on 24 Mar 2020  路  17Comments  路  Source: RocketChat/Rocket.Chat

`version: "3.3"
services:
rocketchat-3000:
image: rocket.chat:2.4.11
environment:
- PORT=3000
- INSTANCE_IP=172.171.117.62
- ROOT_URL=http://172.171.117.62:7777
- MONGO_URL=mongodb://admin:[email protected]:27017/rocketchat?replicaSet=rocketchatReplicaSet&authSource=admin
- MONGO_OPLOG_URL=mongodb://admin:[email protected]:27017/local?replicaSet=rocketchatReplicaSet&authSource=admin
ports:
- 3000:3000
extra_hosts:
- "rocket-7777:172.17.117.62"

rocketchat-7777:
    image: rocket.chat:2.4.11
    environment:
        - PORT=7777
        - INSTANCE_IP=172.171.117.62
        - ROOT_URL=http://172.171.117.62:7777
        - MONGO_URL=mongodb://admin:[email protected]:27017/rocketchat?replicaSet=rocketchatReplicaSet&authSource=admin
        - MONGO_OPLOG_URL=mongodb://admin:[email protected]:27017/local?replicaSet=rocketchatReplicaSet&authSource=admin
    ports:
        - 7777:777
    extra_hosts:
        - "rocket-3000:172.171.117.62"

  `

-------------------------------why 127!!------------------

rocketchat-3000_1 | MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
rocketchat-3000_1 | at Pool. (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/topologies/server.js:431:11)
rocketchat-3000_1 | at emitOne (events.js:116:13)
rocketchat-3000_1 | at Pool.emit (events.js:211:7)
rocketchat-3000_1 | at connect (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:557:14)
rocketchat-3000_1 | at makeConnection (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:39:11)
rocketchat-3000_1 | at callback (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:261:5)
rocketchat-3000_1 | at Socket.err (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:286:7)
rocketchat-3000_1 | at Object.onceWrapper (events.js:315:30)
rocketchat-3000_1 | at emitOne (events.js:116:13)
rocketchat-3000_1 | at Socket.emit (events.js:211:7)
rocketchat-3000_1 | at emitErrorNT (internal/streams/destroy.js:73:8)
rocketchat-3000_1 | at _combinedTickCallback (internal/process/next_tick.js:139:11)
rocketchat-3000_1 | at process._tickCallback (internal/process/next_tick.js:181:9)

All 17 comments

this is not a bug in rocket.chat. your rocket.chat container cant reach your mongodb. try to declare your mongodb container in the same docker-compose file, or put both containers into the same docker network.

do you think we can't use thrid party mongo server?

@bbrauns

we shoud use a mongo server on azure....

If you have any trouble setting up your Rocket.Chat instance, please goto our open Support Channel. Issues are reserved for bugs and feature requests/improvements. Thanks for your comprehension!

@gabriellsh this is not a setup issue, it is a bug, this issue should not have been closed

@arminfelder if you think this is really a bug, you should provide steps to reproduce that. I believe this is rather a set up issue than a bug though.

@luixxiul steps to reproduce:
run the rocketchat 3.1.0 docker image with
MONGO_URL=mongodb://rc-db:27017/rocketchat&authSource=admin
MONGO_OPLOG_URL=mongodb://rc-db:27017/local&authSource=admin

and you will get a connection error, because RC will connect to 127.0.0.1:27017 instead of the defined MONGO_URL (rc-db != 127.0.0.1).
If you leave out &authSource=admin, the MONGO_URL will be used, but of cause authentication will fail, as the user is in the admin db

I'm experiencing the same issue, using the rocket.chat:3.0.12 Docker image.

Adding credentials to the MONGO_URL and MONGO_OPLOG_URL environment variables allows to establish a database connection only if Rocket Chat can reach MongoDB at localhost (for example, running the 2 containers in the same Podman pod).

However, if the MongoDB hostname is something else than localhost and there's authSource=admin in the URL, the connection fails with an error message like the following:

/app/bundle/programs/server/node_modules/fibers/future.js:313
                                                throw(ex);
                                                ^

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
  name: 'MongoNetworkError',
  errorLabels: [Array],
  [Symbol(mongoErrorContextSymbol)]: {}
}]
    at Pool.<anonymous> (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:210:5)
    at /app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:557:14
    at /app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:39:11
    at callback (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:261:5)
    at Socket.<anonymous> (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:300:26)
    at Socket.emit (events.js:210:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {}
}

The connection is attempted towards localhost:27017 and the actual MongoDB host and port are ignored.

@gabriellsh could you please reopen this issue, and give it a high prio, because its blocker for for using RC in a Kubernetes environment, like Azure AKS or GCE

Hello everyone,

I have the same problem too, could you please re-open, it would be nice to use authentication to reach mongo from the Rocket.Chat container.
Thanks.

Hello from my side,

I have the same problem and I've been looking for a solution for hours. Come from this guide and forum, as it is supposed to run on Synology.

https://www.blackvoid.club/rocket-chat-slack-alternative-with-mongodb-as-backend/

https://www.synoforum.com/threads/rocket-chat-slack-alternative-with-mongodb-as-backend.897/page-7

I would appreciate a tip. Thanks.

I have this issue too. Seems to ignore the host portion of the Mongo URI

This issue is affecting us as well

Hello everyone,

I managed to make it work by tweaking the docker-compose.yml as follow:

version: '2'

services:
  rocketchat:
    image: rocket.chat:3.8.1
    command: bash -c 'for i in `seq 1 30`; do node main.js && s=$$? && break || s=$$?; echo "Tried $$i times. Waiting 5 secs..."; sleep 5; done; (exit $$s)'
    restart: unless-stopped
    volumes:
      - ./uploads:/app/uploads
    environment:
      - PORT=3000
      - ROOT_URL=https://mydomain.com
      - MONGO_URL=mongodb://root:mymongopassword@mongo:27017/rocketchat?authSource=admin
      - MONGO_OPLOG_URL=mongodb://root:mymongopassword@mongo:27017/local?authSource=admin
      - ADMIN_USERNAME=admin
      - ADMIN_PASS=admin_password
      - ADMIN_EMAIL=admin_email
    depends_on:
      - mongo
    ports:
      - "127.0.0.1:3000:3000"

  mongo:
    image: mongo:4.2
    restart: unless-stopped
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=mymongopassword
    volumes:
     - ./data/db:/data/db
    command: mongod --oplogSize 128 --replSet rs0
    ports:
      - "127.0.0.1:27017:27017"

  # this container's job is just run the command to initialize the replica set.
  # it will run the command and remove himself (it will not stay running)
  mongo-init-replica:
    image: mongo
    command: 'bash -c "for i in `seq 1 30`; do mongo -u root -p mymongopassword --authenticationDatabase admin mongo/rocketchat --eval \"rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})\" && s=$$? && break || s=$$?; echo \"Tried $$i times. Waiting 5 secs...\"; sleep 5; done; (exit $$s)"'
    depends_on:
      - mongo

Change the mymongopassword.
This way you can connect to the mongo from the host machine and also from the RC container with a real authentication.
Let me know if it works !
Cheers.

MONGO_URL and MONGO_OPLOG_URL are not ignored as stated before.. You have to make sure both env vars are being correctly passed to the container though.

Depending on the password you're using, you might need to escape some characters, for example.. Please take a look at MongoDB documentation https://docs.mongodb.com/manual/reference/connection-string/

I'd also recommend always using quotes on the env var definition.. On docker-compose.yml it should look like this:

    environment:
      - "MONGO_URL=mongodb://rctestuser:mymongopassword@mongo:27017/rocketchat?authSource=admin"
      - "MONGO_OPLOG_URL=mongodb://rctestuser:mymongopassword@mongo:27017/local?authSource=admin"

If using docker run, it should look like this:

docker run \                                                                                                                                                                                                                   -e "MONGO_URL=mongodb://rctestuser:mymongopassword@mongo:27017/rocketchat?authSource=admin" \
-e "MONGO_OPLOG_URL=mongodb://rctestuser:mymongopassword@mongo:27017/local?authSource=admin" \
rocketchat/rocket.chat:3.8.1

If you want to make sure the env vars are correctly set, you can use the command env when running the container and it will show you all env vars the container will have access to:

  • on docker-compose just add: command: env:
version: '2'

services:
  rocketchat:
    image: rocketchat/rocket.chat:latest
    command: env
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
  • on docker run append env to the end of the command:
docker run \
-e "MONGO_URL=mongodb://rctestuser:mymongopassword@mongo:27017/rocketchat?authSource=admin" \
-e "MONGO_OPLOG_URL=mongodb://rctestuser:mymongopassword@mongo:27017/local?authSource=admin" \
rocketchat/rocket.chat:3.8.1 env

@cs35-owncloud @sampaiodiego Thanks for your help with this.

We have now resolved the issue. We ended up migrating from v3.3.0 to the latest release, which appeared to solve the issue.

In case anyone else is interested, this was our final docker-compose file (using an external MongoDB service with a user account in the admin DB):

```yaml
version: '3'

services:
rocketchat:
image: rocketchat/rocket.chat:3.9.0
command: >
bash -c
"for i in seq 1 30; do
node main.js &&
s=$$? && break || s=$$?;
echo "Tried $$i times. Waiting 5 secs...";
sleep 5;
done; (exit $$s)"
restart: unless-stopped
volumes:
- ./uploads:/app/uploads
environment:
- PORT=3000
- ROOT_URL=https://
- MONGO_URL=mongodb://:@:27017/rocketchat?authSource=admin
- MONGO_OPLOG_URL=mongodb://:@:27017/local?replicaSet=rs01&authSource=admin
ports:
- 3000:3000
````

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mddvul22 picture mddvul22  路  3Comments

Buzzele picture Buzzele  路  3Comments

djeber picture djeber  路  3Comments

engelgabriel picture engelgabriel  路  3Comments

danpospisil picture danpospisil  路  3Comments