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:
mnv
2024-10-23 17:21:05 +05:30
committed by GitHub
parent 4cc7c54979
commit 5a9cb9d454
+16 -7
View File
@@ -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: