Dokploy Zero Downtime Deployment Setup
Last Updated: 2025-11-23 Status: Ready for Implementation Applies To: EMTB Production Deployment
Quick Reference​
JSON Configurations (Copy-Paste Ready)​
API Service - Health Check​
{
"Test": ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1"],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 40000000000,
"Retries": 3
}
API Service - Update Config​
{
"Parallelism": 1,
"Delay": 10000000000,
"FailureAction": "rollback",
"Order": "start-first"
}
Frontend Service - Health Check​
{
"Test": ["CMD", "curl", "-f", "http://localhost/health"],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 10000000000,
"Retries": 3
}
Frontend Service - Update Config​
{
"Parallelism": 1,
"Delay": 10000000000,
"FailureAction": "rollback",
"Order": "start-first"
}
Configuration Checklist​
✅ API Service Configuration​
IMPORTANT: These settings are only available for "Application" type, NOT "Compose" type in Dokploy.
Navigation Path:
- Go to Dokploy Dashboard
- Click on "Applications" in the sidebar
- Click on your API application (emtb-api)
- Click the "Advanced" tab (at the top)
- Scroll down to find "Swarm Settings" section
- You should see fields for:
- Health Check
- Restart Policy
- Update Config
- Placement
- Mode
- Resources
Configuration Steps:
- In the "Health Check" field, paste API health check JSON
- In the "Update Config" field, paste API update config JSON
- Click "Save" or "Apply" button
- Click "Redeploy" to apply changes
- Enable Rollbacks in Settings (Recommended)
✅ Frontend Service Configuration​
Navigation Path:
- Go back to "Applications" list
- Click on your Frontend application (emtb-frontend)
- Click the "Advanced" tab
- Scroll to "Swarm Settings" section
Configuration Steps:
- In the "Health Check" field, paste Frontend health check JSON
- In the "Update Config" field, paste Frontend update config JSON
- Click "Save" or "Apply"
- Click "Redeploy" to apply changes
- Enable Rollbacks in Settings (Recommended)
✅ Testing​
- Deploy application
- Keep browser tab open on https://app.emtb.consulting
- Continuously refresh during deployment
- Expected: No "502 Bad Gateway" errors
- Expected: Continuous availability throughout deployment
Time Values Reference​
| Duration | Nanoseconds |
|---|---|
| 10 sec | 10000000000 |
| 30 sec | 30000000000 |
| 40 sec | 40000000000 |
| 60 sec | 60000000000 |
How It Works​
Without Zero Downtime (Current)​
- Dokploy stops old container
- Dokploy starts new container
- Gap period: Container building, starting, running migrations
- Result: 502 Bad Gateway errors during gap
With Zero Downtime (After Configuration)​
- Dokploy starts new container (alongside old one)
- Health checks verify new container is ready
- After 3 successful health checks, traffic switches
- Old container is stopped
- Result: No downtime, seamless transition
Key Configuration Explained​
Order: "start-first"​
Most Critical Setting
- Before: stop-first (causes downtime)
- After: start-first (zero downtime)
- Ensures new container is running before old one stops
StartPeriod​
Grace Period Before Health Checks
- API: 40 seconds (needs time for migrations)
- Frontend: 10 seconds (nginx starts quickly)
- Prevents false failures during container initialization
Retries: 3​
Health Check Verification
- Container must pass 3 consecutive health checks
- If any check fails, counter resets
- Ensures container is truly stable before cutover
FailureAction: "rollback"​
Automatic Recovery
- If new container fails health checks
- Automatically reverts to previous version
- Prevents broken deployments from going live
Troubleshooting​
Issue: Still Seeing 502 Errors​
Check 1: Verify Health Endpoints​
# SSH into API container
docker exec -it emtb-api wget --spider http://localhost:3001/health
# SSH into Frontend container
docker exec -it emtb-frontend curl -f http://localhost/health
Expected: Both should return successfully
Check 2: Verify JSON Format​
- No syntax errors
- All numbers are plain integers (no quotes)
- All strings use double quotes
- Check for trailing commas
Check 3: Check Dokploy Logs​
- Go to application in Dokploy
- Click "Logs"
- Look for health check messages
- Look for error messages during deployment
Check 4: Increase Start Period​
If API takes longer to start:
"StartPeriod": 60000000000 // Increase to 60 seconds
Issue: Health Checks Failing​
Cause 1: curl/wget Not Available​
Frontend uses curl, API uses wget
Solution for Frontend:
# In apps/frontend/Dockerfile
RUN apk add --no-cache curl
Solution for API: Already included âś“
Cause 2: Port Mismatch​
- API health check uses:
localhost:3001 - Frontend health check uses:
localhost - Verify these match your exposed ports
Cause 3: Health Endpoint Not Responding​
Check application logs for errors in the /health endpoint
Current Status​
✅ Already Configured​
- Docker health checks in docker-compose.yml
- Health endpoints implemented:
- API:
/health - Frontend:
/health
- API:
- Traefik labels configured
- Container networking (dokploy-network)
⚠️ Needs Configuration​
- Dokploy Swarm health check settings (see checklist above)
- Dokploy update config with
start-firstorder - Optional: Enable rollbacks
Deployment Process​
Standard Deployment Flow​
- Push code to repository
- Dokploy detects changes (or manual deploy)
- New containers start with health checks
- Health checks monitor new containers
- After 3 successful checks, traffic switches
- Old containers stop gracefully
- Deployment complete - zero downtime âś“
First-Time Configuration Steps​
- Apply Swarm settings (one-time)
- Test deployment
- Verify zero downtime
- Enable rollbacks
- Document any adjustments needed
Additional Optimizations​
CI/CD Integration (Recommended)​
Building on the server consumes resources. Consider:
-
Setup GitHub Actions:
- Build Docker images in CI/CD
- Push to Docker Hub / GitHub Container Registry
- Dokploy pulls pre-built images
-
Benefits:
- Faster deployments
- Less server resource consumption
- No build-related downtime
- Better resource management
Rollback Strategy​
With rollbacks enabled:
- Each deployment creates a snapshot
- Manual rollback to any previous version
- Useful for quick recovery
- Recommended for production
Success Criteria​
After configuration, you should experience:
âś… Zero downtime during deployments âś… No 502 errors when refreshing during deployment âś… Automatic rollback if deployment fails âś… Health verification before traffic switching âś… Graceful transitions between versions
Support​
If Issues Persist​
- Check Dokploy application logs
- Check container logs for health check failures
- Verify JSON configuration syntax
- Confirm health endpoints return 200 OK
- Check Traefik dashboard for routing status
Documentation​
- Official Docs: https://docs.dokploy.com/docs/core/applications/zero-downtime
- GitHub Discussion: https://github.com/Dokploy/dokploy/discussions/492
End of Document