I gave it some thoughts and here is something to get you started.

  1. You will want to persist on your host your config and your db folder. So you can kill your container and restart it if necessary with its config and db content.
  2. You will need a mongod.conf file in a config folder and an empty folder for your db files (WiredTiger’s file system).

Here is my mongod.conf file which you will definitely want to expend on:

replication:
   replSetName: prod
net:
   bindIp: 127.0.0.1

You will most probably do something for the logs, add some authentification mechanism and you will also need to bindIp all the IP addresses that will be able to access this cluster, starting with the other nodes in that same cluster.

mkdir -p ~/mongodb-prod/{config,db}
cd ~/mongodb-prod
vim config/mongod.conf # hack your config file
docker run -d -p 27017:27017 -h $(hostname) --name mongo -v /home/polux/mongodb-prod/config/:/etc/mongo -v /home/polux/mongodb-prod/db/:/data/db mongo:4.4.3 --config /etc/mongo/mongod.conf

Once you have done the same thing on your X servers with X>=3 for a production environment, you can then connect to one of the node and rs.initiate({your-conf}) with something like:

# connect with
docker exec -it mongo mongo

# initiate with
rs.initiate({
      _id: "prod",
      members: [
         { _id: 0, host: "host1:27017" },
         { _id: 1, host: "host2:27017" },
         { _id: 2, host: "host3:27017" }]});

Then your cluster should be ready to work.
Like I said, don’t follow what I just said to the letter ─ but I think it’s a good starting point at least.

Cheers,
Maxime.