services:
mongodb:
image: mongo:8
ports:
- 27017:27017
command: "mongod --replSet rs0"
healthcheck:
test: |
mongosh --quiet --eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }"
interval: 5s
timeout: 5s
retries: 5