This guide covers building and running The Fork application using Docker and Docker Compose.
# Build all images
docker-compose build
# Start all services (mongo, backend, frontend)
docker-compose up
# Access the application
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# API Docs: http://localhost:8000/api/docs
# MongoDB: localhost:27017docker-compose down
# Also remove volumes (database data)
docker-compose down -v# Build
docker build -t fork-backend:latest ./backend
# Run
docker run -d \
-p 8000:8000 \
-e MONGO_URL="mongodb://mongo:27017" \
-e DB_NAME="fork_database" \
-e OPENROUTER_API_KEY="your_key_here" \
-e CORS_ORIGINS="*" \
--name fork-backend \
fork-backend:latest# Build
docker build -t fork-frontend:latest ./frontend
# Run
docker run -d \
-p 3000:3000 \
-e REACT_APP_BACKEND_URL="http://localhost:8000" \
--name fork-frontend \
fork-frontend:latest# Build
docker build -f frontend/Dockerfile.dev -t fork-frontend:dev ./frontend
# Run
docker run -d \
-p 3000:3000 \
-e REACT_APP_BACKEND_URL="http://localhost:8000" \
-v "$(pwd)/frontend/src:/app/src" \
--name fork-frontend-dev \
fork-frontend:dev- Image: mongo:7.0
- Port: 27017
- Default Credentials: admin/password
- Database: fork_database
- Volume: mongo_data (persists between restarts)
- Port: 8000
- Health Check: GET /api/ (every 30s)
- Environment: See docker-compose.yml
- Depends On: MongoDB
- Port: 3000
- Development Mode: Hot reload enabled
- Production Mode: Optimized build via Nginx
- Environment: See docker-compose.yml
- Depends On: Backend
Create .env files in backend and frontend directories:
MONGO_URL=mongodb://admin:password@mongo:27017
DB_NAME=fork_database
OPENROUTER_API_KEY=your_openrouter_api_key
OPENROUTER_MODEL=openai/gpt-4o-mini
CORS_ORIGINS=*
SERVER_HOST=0.0.0.0
SERVER_PORT=8000
REACT_APP_BACKEND_URL=http://localhost:8000
WDS_SOCKET_PORT=443
ENABLE_HEALTH_CHECK=false
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f mongo# Backend
docker-compose exec backend sh
# Frontend
docker-compose exec frontend sh
# MongoDB
docker-compose exec mongo mongosh --username admin --password password# Rebuild images
docker-compose build
# Restart services
docker-compose up# Backend tests
docker-compose exec backend pytest
# Frontend tests (requires different setup)
docker run -it \
-v "$(pwd)/frontend:/app" \
fork-frontend:dev \
yarn testAll services include health checks configured in docker-compose.yml.
# Check service status
docker-compose ps
# View detailed health status
docker inspect fork-backend --format='{{json .State.Health}}' | jqServices communicate through the fork-network bridge network:
- Backend can access MongoDB at
mongodb://mongo:27017 - Frontend can access Backend at
http://backend:8000 - From host: Use
localhostand exposed ports
For production deployments:
- Update CORS_ORIGINS to restrict to your domain
- Use environment secrets instead of .env files
- Add Nginx reverse proxy for SSL/TLS
- Configure MongoDB with proper authentication and backups
- Set resource limits in docker-compose.yml
- Use separate production Dockerfiles optimized for size
- Implement log aggregation (ELK, CloudWatch, etc.)
- Add container monitoring (Prometheus, Grafana, etc.)
# Check MongoDB logs
docker-compose logs mongo
# Verify credentials
docker-compose exec mongo mongosh \
--username admin \
--password password \
--authenticationDatabase admin# Check logs
docker-compose logs backend
# Verify environment variables
docker-compose exec backend env | grep MONGO
# Test database connection
docker-compose exec backend python -c "import pymongo; print(pymongo.__version__)"# Verify backend is running
docker-compose ps backend
# Check REACT_APP_BACKEND_URL
docker-compose exec frontend echo $REACT_APP_BACKEND_URL
# Test from frontend container
docker-compose exec frontend wget http://backend:8000/api/# Find process using port
lsof -i :3000
lsof -i :8000
lsof -i :27017
# Change port in docker-compose.yml or use different port
# e.g., change "3000:3000" to "3001:3000"- Use
.dockerignoreto exclude unnecessary files - Keep images small (use alpine variants when possible)
- Don't run as root in production
- Use multi-stage builds to minimize final image size
- Pin specific versions instead of "latest"
- Use environment variables for configuration
- Implement proper health checks
- Use restart policies for reliability