mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(docker): mongod healthcheck before replica initialization (#56789)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
@@ -9,17 +9,26 @@ services:
|
||||
- 27017:27017
|
||||
volumes:
|
||||
- db-data:/data
|
||||
healthcheck:
|
||||
test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
|
||||
interval: 2s
|
||||
retries: 5
|
||||
|
||||
setup:
|
||||
image: mongo
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
condition: service_healthy
|
||||
restart: on-failure
|
||||
entrypoint: [
|
||||
'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 db:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };'''
|
||||
]
|
||||
# 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 '
|
||||
try {
|
||||
rs.initiate();
|
||||
} catch (err) {
|
||||
if(err.codeName !== "AlreadyInitialized") throw err;
|
||||
}
|
||||
'
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
|
||||
Reference in New Issue
Block a user