I’ve debugged this exact scenario multiple times with self-hosted n8n infrastructure. When the container shows as “running” but you’re getting 502 errors, it usually means the n8n process inside the container has crashed or isn’t listening on the expected port.
Immediate Diagnostic Steps
1. Check n8n Logs (Critical)
docker logs <container-name> --tail 100 --follow
Look for:
- Uncaught exceptions or crashes
- “Address already in use” errors
- Database connection failures
- Memory/OOM errors
2. Verify n8n Process is Actually Running
docker exec <container-name> ps aux | grep n8n
If you don’t see the node process, the container is up but n8n crashed.
3. Test Port Listening Inside Container
docker exec <container-name> netstat -tuln | grep 5678
# or
docker exec <container-name> curl http://localhost:5678/healthz
If port 5678 isn’t listening, n8n isn’t running.
Common Root Causes
Database Connection Lost
- PostgreSQL/MySQL container restarted and n8n lost connection
- Check:
docker logs <db-container>
- Fix: Restart n8n container (not just the n8n service)
Environment Variable Issues
- Missing or changed
N8N_PORT, N8N_HOST, WEBHOOK_URL
- Check:
docker inspect <container-name> and verify env vars
File Permission/Volume Mount Issues
- n8n can’t write to
.n8n directory
- Check:
docker exec <container-name> ls -la /home/node/.n8n
- Fix:
chown -R 1000:1000 /path/to/.n8n on host
Memory Exhaustion
- Workflow with memory leak consumed all RAM
- Check:
docker stats
- Fix: Increase memory limit or identify problematic workflow
Quick Recovery Steps
1. Full Container Restart (not just n8n service)
docker restart <container-name>
# Wait 30 seconds, then check logs
docker logs <container-name> --tail 50
2. If restart fails, recreate container
docker stop <container-name>
docker rm <container-name>
docker-compose up -d # or your docker run command
3. Database connection reset
docker restart <db-container>
sleep 10
docker restart <n8n-container>
Business-Critical Recovery Tip
Since you mentioned this handles CRM/lead automation, I’d recommend:
- Set up health check endpoint monitoring (UptimeRobot, BetterStack)
- Configure container restart policy:
--restart unless-stopped
- Add resource limits to prevent memory exhaustion
- Enable database connection pooling with retry logic
I’ve set up production n8n environments for clients with similar use cases - the most common culprit is database connection loss after an automatic container update or host reboot.
Run those diagnostic commands and share the output if you’re still stuck. Happy to help get you back online!