Restored Mongo in docker compose not working

Description

Ok to explain my problem briefly, I followed the documentation to dump the data from a mongoDB container into a db.dump file, using the following command: docker exec db sh -c "mongodump --archive" > db.dump, I then tried to restore this data in a new mongo container using docker exec -i mongo sh -c "mongorestore --archive" < db.dump then ran an instance of rocket chat connected to this Mongo container, and it worked, however, it’s a different story when using docker-compose.

I tried initially to include a command in the docker-compose file that performs this restoring automatically, here’s what i came up with:

version: ‘2.7.1’
services:
#this is the main mongo database that rocket chat container will be communicating with
mongo:
restart: unless-stopped
image: mongo:4.4
ports:
- “27017:27017”
command: mongod --oplogSize 128 --replSet rs0
container_name: mongo
# this container’s job is just run the command to initialize the replica set. it will run the command and remove himself
mongo-init-replica:
image: mongo:4.4
volumes:
- ./db.dump:/db.dump
command: ‘bash -c “for i in seq 1 20; do mongo 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; (mongorestore --archive=/db.dump && exit $s)”’
depends_on:
- mongo
container_name: mongo-init-replica
# this container is the rocket chat container that uses the mongo service as its mongo database
rocketchat:
restart: unless-stopped
container_name: rocketchat
image: rocket.chat:5.2.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)”
ports:
- “80:3000”
depends_on:
- mongo
environment:
- ROOT_URL=https://localhost
- MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0&directConnection=true
- MONGO_OPLOG_URL=mongodb://mongo:27017/local?replicaSet=rs0&directConnection=true

but, the RC server isn’t just there and I’m taken to the Wizard Setup, i found after some digging that maybe adding this to the RC enviroment will solve my issue : OVERWRITE_SETTING_Show_Setup_Wizard=completed but it didn’t, the only diffrence is that I’m now seeing a login form where the credentials of the previous server aren’t working.

I tried then restoring the data manually, i ran the mongo container alone using docker-compose up mongo -d then the command that restores the data into this container, the logs showed that all documents were restored successfully, but even then, the RC still behaves as if the database is fresh and takes me to the initial setup always (it sometimes throws the error “invalid user” when first accessing the port on which the container is running)

so, I’m confused cause in other cases it works perfectly normal, but when using docker-compose it tends to behave this way

Server Setup Information

  • Version of Rocket.Chat Server: 5.2.0
  • Operating System: windows 10
  • Deployment Method: docker compose
  • Number of Running Instances: one
  • DB Replicaset Oplog: rs0
  • NodeJS Version: 14.x
  • MongoDB Version: 4.4
  • Firewalls involved: no

Any additional Information

logs that shows restoring data was successful :

Hi! While restoring, you can ask mongo to drop any existing collection, like so:

docker exec -i mongo sh -c "mongorestore --archive --drop" < db.dump

What happens here is that, when you start rocketchat before the restoration, it will create some default/initial configuration in some of those collections, so it will clash with the ones you are restoring.

So adding the --drop will drop the existing collections.

If you look closely at the logs, you might see a index error, specially on the settings collection.

Let me know if this helps :slight_smile: