Skip to content

Run mongodb with replica sets using run-rs in docker container

License

Notifications You must be signed in to change notification settings

jineshdoshi/docker-mongodb-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

docker-mongodb-rs

What

  • Dockerfile creates a docker image with ubuntu 20.04, nodejs 16, mongodb 5.0.9 and run-rs

  • run-rs will run a mongodb server with 3 node replica set.

Why

This image can be used for running tests against a mongodb server with replica sets in CI.

How

# build
docker build -t mongodb-rs .

# run
mkdir -p mongodb-data
docker run -d --name mongodb-rs -v `pwd`/mongodb-data:/app/mongodb-data -p 127.0.0.1:27017:27017 -p 127.0.0.1:27018:27018 -p 127.0.0.1:27019:27019 mongodb-rs
docker logs -f mongodb-rs

Note:

  1. To avoid purging of mongodb data append --keep flag to the docker run
  2. To connect and view the db locally on host machine OR using MongoDB Compass, append --bind_ip_all flag to the docker run command
# stop any existing mongodb-rs containers
docker stop mongodb-rs && docker rm -vf mongodb-rs

# re-run with --keep and --bind_ip_all flags
docker run -d --name mongodb-rs -v `pwd`/mongodb-data:/app/mongodb-data -p 127.0.0.1:27017:27017 -p 127.0.0.1:27018:27018 -p 127.0.0.1:27019:27019 mongodb-rs --keep --bind_ip_all

Verify

docker exec mongodb-rs bash -c "curl localhost:27017"

If running with --bind_ip_all then,

curl localhost:27017

How to connect to MongoDB Compass

Note: this only works if --bind_ip_all flag is added

MongoDB Atlas > New Connection > URI: mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs > Connect

Why the version choice:

  1. why nodejs 16 - As of June 19, 2022, current version of run-rs 0.7.6 only works with node v16 or below.
  2. why ubuntu 20.04 - As of June 19, 2022, all of the official nodejs (including v16) docker images use Debain with ARM64. And latest stable version of MongoDB 5.0.9 does not work on Debian with ARM64 but works on Ubuntu 20.04 ARM64.

About

Run mongodb with replica sets using run-rs in docker container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages