Upgrading RC and Mongo DB in docker

if I was in your position, I would use docker inspect on the two containers, to help me rebuild a docker-compose.yml and .env file.
Once I have that I would make a snapshot and then test docker-compose down and docker-compose up to check that it is working. (don’t use ‘latest’ in any image tags)

Next I followed this script to upgrade my mongo DB version. Maybe it helps you:

#!/usr/bin/env bash
read -p "Are you sure? (y/n)" -n 1 -r
echo    # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
sudo docker rm -f rocketchat-mongo-upgrade
set -e
sudo docker pull mongo:4.2.17
sudo docker pull mongo:4.4.9
sudo docker pull mongo:5.0.3
sudo docker-compose stop
sudo docker start rocketchat-mongo
until sudo docker exec rocketchat-mongo mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
sudo docker exec -u0 rocketchat-mongo rm -r -f /dump
sudo docker exec -u0 rocketchat-mongo mkdir /dump
echo "Starting dump.."
sudo docker exec -u0 rocketchat-mongo mongodump --out=/dump
sudo docker exec -u0 rocketchat-mongo tar -czf /dump.tgz /dump
sudo docker cp rocketchat-mongo:/dump.tgz dump.tgz
echo "Backup complete. Stopping old Mongo"
sudo docker stop rocketchat-mongo
sudo rm -r -f data  #data is where my mongo database bind mount is
echo "Starting new Mongo.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.0.25 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
sudo docker cp dump.tgz rocketchat-mongo-upgrade:/dump.tgz
sudo docker exec rocketchat-mongo-upgrade tar -xzf /dump.tgz
until sudo docker exec rocketchat-mongo-upgrade mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
echo "Initializing Mongo..."
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "rs.initiate({_id: 'rs0', members: [ { _id: 0, host: 'localhost:27017' } ]})"
echo "Restoring database.."
sudo docker exec -u0 rocketchat-mongo-upgrade mongorestore /dump
echo "Cleaning up.."
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
sudo rm dump.tgz
echo
echo "Upgrading mongo verstion to 4.2.17.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.2.17 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
until sudo docker exec rocketchat-mongo-upgrade mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.2\" } )"
sudo docker logs rocketchat-mongo-upgrade
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
echo
echo "Upgrading mongo verstion to 4.4.9.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.4.9 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
until sudo docker exec rocketchat-mongo-upgrade mongo
do
   echo "Waiting for Mongo to start..."
   sleep 1
done
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.4\" } )"
sudo docker logs rocketchat-mongo-upgrade
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
echo
echo "Cleaning up container images."
sudo docker image prune -a
1 Like