Skip to content

Mongodb with replicaset running in docker

Notifications You must be signed in to change notification settings

javilobo8/mongors

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

A simple docker compose file to run a mongodb database in docker with replica set on.

Requirements

  • Install Docker and docker compose if you don't have them already.

Installation

  1. Clone the repository:
git clone https://github.com/javilobo8/mongors.git && cd mongors
  1. Copy default configuration to .env file:
cp .env.example .env
  1. Apply the configuration you want to the .env file:
  • RS -> The replicas set name (Default: rs0)
  • HOST -> The replica set host (Default: 127.0.0.1)
  • PORT -> The replica set port (Default: 27017)
  • DATA -> The folder where the database information will be stored (Default: ./data/db)
  1. Start the container
docker compose up -d
  1. Initialize the replica set (Only the first time you run the container)
docker exec -it rs0 mongosh # This will open the mongo shell
rs.initiate() # This will initialize the replica set
rs.status() # This will show the replica set status
exit # This will exit the mongo shell

Updating from previous versions

If you are updating from a previous version, you will need to remove the old container and create a new one. To do so, follow these steps:

  1. Stop the container
docker compose down
  1. Remove the container
docker rm rs0
  1. Check mongodb version in compose.yml file and update it if needed
  2. Start the container
docker compose up -d

About

Mongodb with replicaset running in docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published