chore: initiate replica with defined host (#62477)

This commit is contained in:
Shaun Hamilton
2025-10-07 11:43:27 +02:00
committed by GitHub
parent c8aeac5ce8
commit 806be69c88
2 changed files with 11 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ services:
container_name: mongodb
command: mongod --replSet rs0
restart: unless-stopped
hostname: mongodb
ports:
- 27017:27017
volumes:
@@ -22,8 +23,14 @@ services:
# This will try to initiate the replica set, until it succeeds twice (i.e. until the replica set is already initialized)
command: >
mongosh --host db:27017 --eval '
var cfg = {
_id: "rs0",
members: [
{ _id: 0, host: "mongodb:27017" }
]
};
try {
rs.initiate();
rs.initiate(cfg);
} catch (err) {
if(err.codeName !== "AlreadyInitialized") throw err;
}