I want to use Mongo with transactions so I am trying to set up a replica set (containing only one Mongo node) with docker.
I want to automatically run rs.initiate() once my database starts up. To do this, I'm using a script in docker-entrypoint-initdb.d.
I also need to start the mongo node with the replSet option, so I updated the entrypoint value. When the entrypoint is my new command, the scripts I have in docker-entrypoint-initdb.d does not run. When I comment out my new entrypoint, the scripts do run.
I know I could wrap my docker-compose up command and a docker-exec ... 'rs.initiate()' command together in a script and call that instead of docker-compose, but that feels like a hack.
How can I make a Mongo node with a replSet and run rs.initiate()?
docker-compose.yaml:
version: "3"
services:
order-db:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: mongo
# entrypoint: ["mongod", "--bind_ip_all", "--replSet", "order"]
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
- ./docker-entrypoint-initdb.d/run.sh:/docker-entrypoint-initdb.d/run.sh:ro
- ./docker-entrypoint-initdb.d/arun.sh:/docker-entrypoint-initdb.d/arun.sh:ro
docker-entrypoint-initdb.d/mongo-init.js:
rs.initiate();
db.createCollection("just-testing-to-see-if-this-file-runs");
docker-entrypoint-initdb.d/a-run.sh:
echo "running aaaaaaaaaaaaaaaaaaaaaaaaaaa"
docker-entrypoint-initdb.d/run.sh:
echo "running!!!!!!!!"