diff --git a/backend/docker-compose.dev.yml b/backend/docker-compose.dev.yml index 9b97c8e..5a43056 100644 --- a/backend/docker-compose.dev.yml +++ b/backend/docker-compose.dev.yml @@ -35,11 +35,12 @@ services: networks: - normogen-network healthcheck: - test: ['CMD', 'mongosh', '--eval', 'db.adminCommand.ping()'] + test: | + mongosh --eval "db.adminCommand('ping').ok" --quiet interval: 10s timeout: 5s retries: 5 - start_period: 10s + start_period: 40s volumes: mongodb_dev_data: driver: local diff --git a/backend/docker/MONGODB-HEALTHCHECK-FIX.md b/backend/docker/MONGODB-HEALTHCHECK-FIX.md new file mode 100644 index 0000000..65e4b4a --- /dev/null +++ b/backend/docker/MONGODB-HEALTHCHECK-FIX.md @@ -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`