Deploy RocketChat and MongoDB on different Hosts [Docker]

Description

Hello guys,
I am trying to deploy RocketChat and MongoDB on different Hosts with Docker.
RocketChat on Host 192.168.56.11
MongoDB on Host 192.168.56.22

I am using the commands specified in here: https://hub.docker.com/_/rocket-chat

$ docker run --name db -d mongo:4.0 --smallfiles --replSet rs0 --oplogSize 128

$ docker exec -ti db mongo --eval “printjson(rs.initiate())”

Now im struggling with this part:

If you’re using a third party Mongo provider, or working with Kubernetes, you need to override the MONGO_URL environment variable:

$ docker run --name rocketchat -p 80:3000 --env ROOT_URL=http://localhost --env MONGO_URL=mongodb://mymongourl/mydb --env MONGO_OPLOG_URL=mongodb://mymongourl:27017/local -d rocket.chat

I followed this topic, which is similar with a different deployment method: How configure Rocket Chat and MongoDB in separatelly hosts?
So first I tried to deploy RC by using following parameters:

MONGO_URL=mongodb://192.168.56.22:27017/rocketchat?replicaSet=rs0
MONGO_OPLOG_URL=mongodb://192.168.56.22:27017/local?replicaSet=rs0
and also
MONGO_URL=mongodb://192.168.56.22:27017/rocketchat
MONGO_OPLOG_URL=mongodb://192.168.56.22:27017/local

Both versions gives me an error.

I also tried changing the mongod.conf within the container to:
net:
port: 27017
bindIp: 0.0.0.0 ##normally its 127.0.0.1

How can I define a specific container for these parameters?

I would be very thankful for any help.

Server Setup Information

  • Version of Rocket.Chat Server:
  • Operating System: Ubuntu 18.04
  • Deployment Method: Docker
  • Number of Running Instances: one on each host
  • DB Replicaset Oplog: enabled
  • NodeJS Version: 12.16.1 - x64
  • MongoDB Version: 4.0.20
  • Proxy: nginx
  • Firewalls involved: none

You need to expose the mongodb Port.

So in your case: docker run --name db -d mongo:4.0 --smallfiles --replSet rs0 --oplogSize 128 -p 192.168.56.22:27017:27017

After that, you can access mongodb on port 27017 via IP 192.168.56.22.

thank you for your reply.

I have found a different solution to solve the problem. I created a new Docker network with the same IP range that the hosts have. Then I assigned an IP address to the container, which allowed me to access them like this:
MONGO_URL=mongodb://ip_container:27017/rocketchat?replicaSet=rs0
MONGO_OPLOG_URL=mongodb:/ip_container:27017/local?replicaSet=rs0

But your solution is much more simple and works too.