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")
- quick start without extra steps and preparing (if you have docker)
- automatically inserting variables into the mongod.conf file
- minimal required settings
- mongo-init.sh creates users and shutdowns mongod
- docker runs mongod
- replica set is initialized in healthcheck
- 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
docker compose up -d
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,
...
}
docker compose down
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).