Skip to content

jovani-x/docker-mongo-replica-init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Docker with mongo and automatic initialization of replication

It is a simple way to run mongoDB with automatic initialization of replica in one command only.

It's just for local development only due to: WARN: SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "MONGO_KEY_PATH" and "MONGO_KEY_NAME")

Features:

  • quick start without extra steps and preparing (if you have docker)
  • automatically inserting variables into the mongod.conf file
  • minimal required settings

Details:

  • mongo-init.sh creates users and shutdowns mongod
  • docker runs mongod
  • replica set is initialized in healthcheck

Usual way:

  • run mongod without replica set
  • connect to it
  • create admin user
  • create app db user
  • restart mongod with replica set (shutdown and run again)
  • auth and init replica

Run

1. Start mongo image

docker compose up -d

2. Wait a little bit and check replica status

in terminal:

docker exec -it mongo_app_container mongosh --authenticationDatabase admin -u superuser -p superuserpass appdb --eval "rs.status();"

or in the docker container terminal:

mongosh --authenticationDatabase admin -u superuser -p superuserpass appdb --eval "rs.status();"
/*
mongo_app_container - container name
admin - admin db name
superuser - admin user name
superuserpass - admin user password
appdb - app db name
*/

answer should be something like:

{
	...
	set: 'replicaSetCustomName',
	...
	ok: 1,
	...
}

3. Stop mongo image

docker compose down

Extra info and refs to the official docs

Localhost Exception

Use SCRAM to Authenticate Clients on Self-Managed Deployments

Default etrypoint of mongo image is /usr/local/bin/docker-entrypoint.sh.

Some extra scripts can be added to /docker-entrypoint-initdb.d/ (these scripts run once only).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors