mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 10:22:16 +00:00
chore: initiate replica with defined host (#62477)
This commit is contained in:
@@ -13,6 +13,7 @@ services:
|
||||
image: mongo
|
||||
command: mongod --replSet rs0
|
||||
restart: unless-stopped
|
||||
hostname: mongodb
|
||||
volumes:
|
||||
- mongodb-data:/data/db
|
||||
mongo-setup:
|
||||
@@ -24,8 +25,9 @@ services:
|
||||
'bash',
|
||||
'-c',
|
||||
# This will try to initiate the replica set, until it succeeds twice (i.e. until the replica set is already initialized)
|
||||
'mongosh --host mongo-db:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };'''
|
||||
'mongosh --host mongo-db:27017 --eval ''try {var cfg = { _id: "rs0", members: [{ _id: 0, host: "mongodb:27017" }] }; rs.initiate(cfg); } catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };'''
|
||||
]
|
||||
|
||||
volumes:
|
||||
mongodb-data:
|
||||
driver: local
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user