Skip to content

DavyBello/mongo-replica-set

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB Replica Set

A Replica Set of MongoDB running in a Docker container

Not For Production

The key motivation for this image is to have a ready-made replica set of MongoDB running inside docker container for CI tests and local development.

To run the container, execute the following command:

docker run -d -p 27017:27017 -p 27018:27018 -p 27019:27019 candis/mongo-replica-set

Wait for 30 to 35 seconds in order to properly start all database instances and replica-set initialization.

Once ready, the replica-set can be accessed using the following connection string:

mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0&readPreference=primary&ssl=false

Configuration

Host

You can pass an env variable called HOST when running the container to configure the replica's hostname in docker. By default, it uses localhost.

If you're connecting from your host machine, you might need to set a new alias within /etc/hosts:

# /etc/hosts
127.0.0.1 HOST # where HOST is the value passed as env variable to the container

Replica Set Name

You can pass the REPLICA_SET_NAME env variable to configure the replica set name. By default, it uses rs0.

Startup Parameters

You can also pass additional startup parameters to the mongod process by overriding the docker COMMAND.

For example from docker-compose

mongo:
  image: davybello/mongo-replica-set:5.0.12
  command: "--setParameter transactionLifetimeLimitSeconds=3600"

Or from the command line like

docker run davybello/mongo-replica-set:5.0.12 --setParameter transactionLifetimeLimitSeconds=3600

About

A replica set of MongoDB in Docker Container

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Shell 52.7%
  • Dockerfile 47.3%