fix(docker): Fix MongoDB healthcheck configuration
This commit is contained in:
parent
d63f160af3
commit
b218594b53
2 changed files with 63 additions and 2 deletions
|
|
@ -35,11 +35,12 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- normogen-network
|
- normogen-network
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ['CMD', 'mongosh', '--eval', 'db.adminCommand.ping()']
|
test: |
|
||||||
|
mongosh --eval "db.adminCommand('ping').ok" --quiet
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 40s
|
||||||
volumes:
|
volumes:
|
||||||
mongodb_dev_data:
|
mongodb_dev_data:
|
||||||
driver: local
|
driver: local
|
||||||
|
|
|
||||||
60
backend/docker/MONGODB-HEALTHCHECK-FIX.md
Normal file
60
backend/docker/MONGODB-HEALTHCHECK-FIX.md
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
# MongoDB Health Check Fix
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
The MongoDB container was failing health checks with the original configuration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
healthcheck:
|
||||||
|
test: ['CMD', 'mongosh', '--eval', 'db.adminCommand.ping()']
|
||||||
|
start_period: 10s # Too short!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Root Causes
|
||||||
|
1. **start_period too short**: 10s isn't enough for MongoDB to initialize, especially on first start
|
||||||
|
2. **Command format**: The healthcheck needs proper output handling
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
Updated healthcheck in docker-compose.dev.yml:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
healthcheck:
|
||||||
|
test: |
|
||||||
|
mongosh --eval "db.adminCommand('ping').ok" --quiet
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
start_period: 40s # Increased from 10s to 40s
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changes Made
|
||||||
|
- ✅ Increased `start_period` from 10s to 40s (gives MongoDB time to initialize)
|
||||||
|
- ✅ Simplified the healthcheck command to use shell format
|
||||||
|
- ✅ Added `--quiet` flag to suppress verbose output
|
||||||
|
|
||||||
|
## How to Apply
|
||||||
|
On your server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Pull the latest changes
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# Stop and remove existing containers
|
||||||
|
docker compose -f docker-compose.dev.yml down -v
|
||||||
|
|
||||||
|
# Start fresh
|
||||||
|
docker compose -f docker-compose.dev.yml up -d
|
||||||
|
|
||||||
|
# Watch the logs
|
||||||
|
docker compose -f docker-compose.dev.yml logs -f mongodb
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verify Health Check
|
||||||
|
```bash
|
||||||
|
# Check container health
|
||||||
|
docker ps --format "table {{.Names}} {{.Status}}"
|
||||||
|
|
||||||
|
# Check health status specifically
|
||||||
|
docker inspect normogen-mongodb-dev --format='{{.State.Health.Status}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected output: `healthy`
|
||||||
Loading…
Add table
Add a link
Reference in a new issue