This guide explains how to set up and run ImaForm using Docker and Docker Compose. Docker provides a consistent environment for development and production deployments.
-
Docker: Version 24.0 or higher
- Download Docker Desktop (Windows/Mac)
- Install Docker Engine (Linux)
-
Docker Compose: Version 2.0 or higher
- Included with Docker Desktop
- Install separately on Linux: Docker Compose Install Guide
- Minimum: 8GB RAM, 2 CPU cores
- Recommended: 16GB RAM, 4 CPU cores
- GPU: NVIDIA GPU with CUDA support (optional but recommended for geometry engine)
- Windows 10/11 (with WSL2)
- macOS 10.15+ (with Docker Desktop)
- Linux (Ubuntu 20.04+, Debian 11+, etc.)
git clone https://github.com/your-org/imaform.git
cd imaform# Copy environment file template
cp docker/.env.example docker/.env
# Edit the .env file with your configuration
nano docker/.envImportant: Update the following values in .env:
SECRET_KEY: Generate a secure key withopenssl rand -hex 32DATABASE_URL: Update if using external databaseREDIS_URL: Update if using external RedisCORS_ORIGINS: Add your domain for production
# Build all images
./scripts/docker/build.sh
# Or build with options
./scripts/docker/build.sh --no-cache --pull# Start all containers (detached)
./scripts/docker/up.sh
# Or start in foreground to see logs
./scripts/docker/up.sh --foreground# Check health of all services
./scripts/docker/health-check.sh- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Nginx: http://localhost:80
For development with hot reload, use the development scripts:
# Start development containers with hot reload
./scripts/dev/docker/dev-up.sh
# Rebuild specific service
./scripts/dev/docker/rebuild.sh --service backend
# Stop development containers
./scripts/dev/docker/dev-down.sh- Frontend: Next.js hot reload enabled
- Backend: Uvicorn auto-reload enabled
- Celery Worker: Auto-reload enabled
- Make code changes in your local directory
- Changes are automatically reflected in containers (via volume mounts)
- View logs:
./scripts/docker/logs.sh --follow - Restart service if needed:
./scripts/dev/docker/rebuild.sh --service <service>
For production deployment:
# 1. Configure production environment
nano docker/.env
# Set ENVIRONMENT=production
# Update SECRET_KEY with a secure value
# 2. Configure SSL certificates (optional but recommended)
mkdir -p docker/nginx/ssl
# Place cert.pem and key.pem in docker/nginx/ssl/
# 3. Start production containers
./scripts/deploy/docker/prod-up.sh
# 4. Wait for services to be ready
./scripts/docker/wait-for-services.sh --timeout 300- SSL/TLS: Configure SSL certificates in
docker/nginx/ssl/ - Environment: Set
ENVIRONMENT=productionin.env - Secrets: Use strong, randomly generated secrets
- Backups: Set up regular backups using
./scripts/deploy/docker/backup.sh - Monitoring: Configure monitoring and alerting
# View all logs
./scripts/docker/logs.sh
# Follow logs in real-time
./scripts/docker/logs.sh --follow
# View specific service logs
./scripts/docker/logs.sh --service backend --follow# Stop all containers
./scripts/docker/down.sh
# Stop and remove volumes (WARNING: Data loss)
./scripts/docker/down.sh --volumes# Remove all containers, volumes, and images
./scripts/docker/clean.sh --volumes --images --cache
# Clean without confirmation
./scripts/docker/clean.sh --force# Backup database and storage
./scripts/deploy/docker/backup.sh --type all
# Backup only database
./scripts/deploy/docker/backup.sh --type database
# Backup only storage
./scripts/deploy/docker/backup.sh --type storageProblem: Container fails to start immediately
Solutions:
- Check logs:
./scripts/docker/logs.sh --service <service> - Verify environment variables in
docker/.env - Check port conflicts:
netstat -tuln | grep LISTEN(Linux) ornetstat -an(Mac/Windows) - Verify Docker is running:
docker ps
Problem: Containers are killed due to OOM (Out of Memory)
Solutions:
- Increase Docker memory limit in Docker Desktop settings
- Reduce worker concurrency in
.env:CELERY_WORKER_CONCURRENCY=1 - Stop unused containers:
docker system prune -f
Problem: Geometry engine can't access GPU
Solutions:
- Verify NVIDIA driver is installed:
nvidia-smi - Check Docker GPU support:
docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi - Ensure
CUDA_VISIBLE_DEVICESis set in.env - Restart Docker Desktop with GPU support enabled
Problem: Backend can't connect to PostgreSQL
Solutions:
- Check PostgreSQL is running:
docker ps | grep postgres - Verify database URL in
.env - Check PostgreSQL logs:
./scripts/docker/logs.sh --service postgres - Wait for PostgreSQL to be ready:
./scripts/docker/wait-for-services.sh --service postgres
Problem: Can't write to storage directory
Solutions:
- Check storage directory permissions:
ls -la storage/ - Fix permissions:
chmod -R 777 storage/(development only) - Ensure storage directory exists:
mkdir -p storage/{uploads,exports,cache}
Edit docker/.env to change default ports:
NGINX_HTTP_PORT=8080
POSTGRES_PORT=5433
REDIS_PORT=6380Configure ImaForm to use external PostgreSQL or Redis:
DATABASE_URL=postgresql+asyncpg://user:pass@external-host:5432/dbname
REDIS_URL=redis://external-host:6379/0Configure GPU usage in .env:
CUDA_VISIBLE_DEVICES=0 # Use GPU 0
# or
CUDA_VISIBLE_DEVICES=0,1 # Use GPUs 0 and 1
# or
CUDA_VISIBLE_DEVICES="" # Disable GPU (CPU only)Adjust worker count based on available CPU cores:
CELERY_WORKER_CONCURRENCY=4 # 4 workersBackend runs with 4 workers by default. Adjust in docker/backend/Dockerfile:
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "8"]Tune PostgreSQL in docker/docker-compose.yml:
postgres:
command:
- "postgres"
- "-c"
- "max_connections=200"
- "-c"
- "shared_buffers=256MB"- Never commit
.envto version control - Use strong, random secrets:
openssl rand -hex 32 - Enable SSL/TLS in production
- Restrict CORS origins: Only allow your domain
- Regular updates: Keep Docker images updated
- Monitor logs: Check for suspicious activity
- Backup regularly: Schedule automated backups
For issues or questions:
- GitHub Issues: https://github.com/your-org/imaform/issues
- Documentation: https://docs.imaform.com
- Community: https://community.imaform.com