4.7 KiB
✅ Coolify Deployment - FIXED!
What Was Wrong
Error: Bind for 0.0.0.0:8000 failed: port is already allocated
Cause: Your docker-compose.yml used ports: which tries to bind to the host's ports. Coolify uses Traefik reverse proxy, so it doesn't need (and conflicts with) port bindings.
What I Fixed
Changed in docker-compose.yml:
Before:
backend:
ports:
- "8000:8000" # ❌ Binds to host, causes conflict
frontend:
ports:
- "5173:5173" # ❌ Binds to host, causes conflict
After:
backend:
expose:
- "8000" # ✅ Internal only, Coolify handles routing
frontend:
expose:
- "5173" # ✅ Internal only, Coolify handles routing
Files Created for Production Deployment
- frontend/Dockerfile.prod - Production-optimized multi-stage build with Nginx
- frontend/nginx.conf - Nginx config with API proxy and WebSocket support
- docker-compose.coolify.yml - Full production-ready config
- COOLIFY_DEPLOYMENT.md - Complete deployment guide
Next Steps
Option 1: Quick Deploy (Use Modified docker-compose.yml)
The main docker-compose.yml is now fixed. Just:
-
Commit and push:
git add docker-compose.yml git commit -m "Fix Coolify port binding" git push -
In Coolify UI:
- Trigger a new deployment
- It should work now!
-
Configure environment variables in Coolify:
JWT_SECRET=your-secure-secret-key-min-32-chars VITE_API_URL=https://your-domain.com/api VITE_WS_URL=wss://your-domain.com
Option 2: Full Production Setup (Recommended for Production)
Use the production-ready configuration:
-
Update your repository:
git add . git commit -m "Add production Dockerfile and Coolify config" git push -
In Coolify UI:
- Set "Docker Compose File" to:
docker-compose.coolify.yml - Or keep using
docker-compose.yml(now fixed)
- Set "Docker Compose File" to:
-
Configure routing in Coolify:
- Backend service: Port 8000
- Frontend service: Port 80 (if using Dockerfile.prod) or 5173 (if using dev)
Testing After Deployment
Once deployed successfully:
# Test backend API
curl https://your-domain.com/docs
# Test frontend
https://your-domain.com
What Each File Does
| File | Purpose | When to Use |
|---|---|---|
| docker-compose.yml | Development + Coolify compatible | Default, now fixed |
| docker-compose.coolify.yml | Production optimized for Coolify | Production deployments |
| frontend/Dockerfile.prod | Multi-stage production build | Production (better performance) |
| frontend/nginx.conf | Nginx reverse proxy config | With Dockerfile.prod |
Configuration in Coolify UI
Environment Variables to Set:
# Required
JWT_SECRET=<generate-secure-random-32-char-string>
# Optional - Coolify can auto-configure these
VITE_API_URL=https://your-app.your-domain.com/api
VITE_WS_URL=wss://your-app.your-domain.com
Port Configuration:
Backend:
- Internal Port:
8000 - Public: Yes (if you want direct API access) or route via frontend proxy
Frontend:
- Internal Port:
5173(dev) or80(prod) - Public: Yes
- Root path:
/
Troubleshooting
Still Getting Port Error?
- Check if there's an old deployment in Coolify
- In Coolify UI, stop/delete old deployment
- Retry
Build Fails?
Check logs for:
- Missing
email-validator==2.1.1in requirements.txt ✅ (already fixed) - Frontend build errors - check
package.jsonhasbuildscript
Can't Access API from Frontend?
Update frontend environment variables:
VITE_API_URL=/api # Relative URL if on same domain
Or use nginx proxy (already configured in nginx.conf).
Deployment Checklist
- ✅ Port bindings removed (expose instead)
- ✅ email-validator added to requirements.txt
- ✅ Production Dockerfile created for frontend
- ✅ Nginx config created with API proxy
- ✅ Environment variables documented
- ⏳ Commit and push changes
- ⏳ Configure Coolify environment variables
- ⏳ Deploy in Coolify
- ⏳ Test the deployment
Quick Commands
# Commit all fixes
git add .
git commit -m "Fix Coolify deployment: remove port bindings, add production config"
git push
# Test locally (optional)
docker compose up -d
docker compose ps
docker compose logs -f
# Stop local
docker compose down
Summary
✅ Main issue FIXED: Changed ports: to expose: in docker-compose.yml
✅ Production ready: Created Dockerfile.prod and nginx.conf for optimal deployment
✅ Coolify compatible: No more port binding conflicts
🚀 Next: Commit, push, and redeploy in Coolify!
The deployment should work now! The port allocation error will be resolved. 🎉