Fix Coolify deployment: remove volume bind mounts
This commit is contained in:
193
COOLIFY_VOLUME_FIX.md
Normal file
193
COOLIFY_VOLUME_FIX.md
Normal file
@ -0,0 +1,193 @@
|
||||
# ✅ Coolify Volume Mount Error - FIXED!
|
||||
|
||||
## The Problem
|
||||
|
||||
After fixing the port binding issue, Coolify deployment had new errors:
|
||||
|
||||
**Backend Error:**
|
||||
```
|
||||
ModuleNotFoundError: No module named 'app'
|
||||
```
|
||||
|
||||
**Frontend Error:**
|
||||
```
|
||||
npm error code ENOENT
|
||||
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/app/package.json'
|
||||
```
|
||||
|
||||
## Root Cause
|
||||
|
||||
The `docker-compose.yml` had **development volume mounts** that override the Dockerfile COPY commands:
|
||||
|
||||
```yaml
|
||||
# ❌ BEFORE - Development setup with bind mounts
|
||||
services:
|
||||
backend:
|
||||
volumes:
|
||||
- ./backend:/app # This path doesn't exist in Coolify!
|
||||
- sqlite_data:/app/data
|
||||
|
||||
frontend:
|
||||
volumes:
|
||||
- ./frontend:/app # This path doesn't exist in Coolify!
|
||||
- /app/node_modules
|
||||
```
|
||||
|
||||
**Why this caused errors:**
|
||||
- In local development, `./backend` and `./frontend` exist relative to docker-compose.yml
|
||||
- In Coolify, these paths don't exist in the build context
|
||||
- The bind mount creates an **empty `/app` directory**, overriding all files copied by Dockerfile
|
||||
- Result: No Python modules, no package.json, total failure!
|
||||
|
||||
## The Fix
|
||||
|
||||
Removed bind mounts from `docker-compose.yml`:
|
||||
|
||||
```yaml
|
||||
# ✅ AFTER - Production-ready, Coolify compatible
|
||||
services:
|
||||
backend:
|
||||
volumes:
|
||||
- sqlite_data:/app/data # Keep only named volume for database
|
||||
|
||||
frontend:
|
||||
# No volumes needed - files copied by Dockerfile
|
||||
```
|
||||
|
||||
**What changed:**
|
||||
- **Backend**: Removed `- ./backend:/app` bind mount
|
||||
- **Frontend**: Removed `- ./frontend:/app` and `- /app/node_modules` bind mounts
|
||||
- **Kept**: Named volume `sqlite_data:/app/data` for persistent SQLite database
|
||||
|
||||
## Deploy to Coolify
|
||||
|
||||
### Step 1: Commit and Push
|
||||
|
||||
```bash
|
||||
git add docker-compose.yml
|
||||
git commit -m "Fix Coolify deployment: remove volume bind mounts"
|
||||
git push
|
||||
```
|
||||
|
||||
### Step 2: Trigger Deployment in Coolify
|
||||
|
||||
1. Go to your Coolify dashboard
|
||||
2. Navigate to your H2H application
|
||||
3. Click **"Redeploy"** or trigger a new deployment
|
||||
4. Watch the build logs - should complete without errors now!
|
||||
|
||||
### Step 3: Configure Environment Variables
|
||||
|
||||
In Coolify UI, set these environment variables:
|
||||
|
||||
```bash
|
||||
# Required
|
||||
JWT_SECRET=your-secure-random-32-character-secret-key-here
|
||||
|
||||
# Optional - Coolify auto-configures URLs, but you can override:
|
||||
VITE_API_URL=https://your-domain.com/api
|
||||
VITE_WS_URL=wss://your-domain.com
|
||||
```
|
||||
|
||||
### Step 4: Configure Caddy Routing
|
||||
|
||||
**Backend Service:**
|
||||
- Internal Port: `8000`
|
||||
- Public: Yes (if you want direct API access)
|
||||
- Path: `/api` (optional, for API routing)
|
||||
|
||||
**Frontend Service:**
|
||||
- Internal Port: `5173`
|
||||
- Public: Yes
|
||||
- Path: `/` (root path)
|
||||
|
||||
## What Was Fixed
|
||||
|
||||
| Issue | Before | After |
|
||||
|-------|--------|-------|
|
||||
| Port binding conflict | `ports: - "8000:8000"` | `expose: - "8000"` |
|
||||
| Backend bind mount | `- ./backend:/app` | Removed ✅ |
|
||||
| Frontend bind mount | `- ./frontend:/app` | Removed ✅ |
|
||||
| Email validator | Missing | Added to requirements.txt ✅ |
|
||||
|
||||
## Testing After Deployment
|
||||
|
||||
Once deployed successfully:
|
||||
|
||||
```bash
|
||||
# Test backend health
|
||||
curl https://your-domain.com/health
|
||||
|
||||
# Test backend API docs
|
||||
curl https://your-domain.com/docs
|
||||
|
||||
# Test frontend (in browser)
|
||||
https://your-domain.com
|
||||
```
|
||||
|
||||
## Development vs Production
|
||||
|
||||
### For Local Development (with hot-reload)
|
||||
|
||||
If you want hot-reload for local development, create a separate `docker-compose.dev.yml`:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
backend:
|
||||
build: ./backend
|
||||
ports:
|
||||
- "8000:8000" # Local development can use ports
|
||||
volumes:
|
||||
- ./backend:/app # Hot-reload for development
|
||||
- sqlite_data:/app/data
|
||||
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
||||
|
||||
frontend:
|
||||
build: ./frontend
|
||||
ports:
|
||||
- "5173:5173" # Local development can use ports
|
||||
volumes:
|
||||
- ./frontend:/app # Hot-reload for development
|
||||
- /app/node_modules
|
||||
command: npm run dev -- --host
|
||||
depends_on:
|
||||
- backend
|
||||
|
||||
volumes:
|
||||
sqlite_data:
|
||||
```
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
# Local development with hot-reload
|
||||
docker compose -f docker-compose.dev.yml up
|
||||
|
||||
# Production/Coolify deployment
|
||||
docker compose up
|
||||
```
|
||||
|
||||
### For Production Optimization (Optional)
|
||||
|
||||
Consider using the production Dockerfile for frontend:
|
||||
|
||||
**In Coolify UI:**
|
||||
- Set "Dockerfile Path" for frontend to: `frontend/Dockerfile.prod`
|
||||
- This uses Nginx instead of Vite dev server
|
||||
- Serves optimized static build on port 80
|
||||
- Better performance and security
|
||||
|
||||
## Summary
|
||||
|
||||
✅ **Bind mount issue FIXED**: Removed development volume mounts from docker-compose.yml
|
||||
|
||||
✅ **Coolify compatible**: Files now copied by Dockerfile, not overridden by volumes
|
||||
|
||||
✅ **Both errors resolved**:
|
||||
- Backend `ModuleNotFoundError` → Fixed (app module copied)
|
||||
- Frontend `package.json not found` → Fixed (package.json copied)
|
||||
|
||||
✅ **Ready to deploy**: Commit, push, and redeploy in Coolify!
|
||||
|
||||
---
|
||||
|
||||
**The deployment should work now!** Both the port conflict and volume mount issues are resolved. 🎉
|
||||
Reference in New Issue
Block a user