> ## Documentation Index
> Fetch the complete documentation index at: https://docs.figorisk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker Deployment

> Deploy FigoRisk using Docker Compose

## Overview

Docker Compose provides the simplest way to deploy FigoRisk. All services are defined in a single configuration file and can be started with one command.

<Info>
  **Recommended for**: Development, testing, small to medium production deployments
</Info>

***

## Deployment Package Structure

```
figorisk-deployment-package/
├── docker-compose.yml         # Service definitions
├── nginx.conf                 # Nginx configuration
├── .env.template              # Environment template
├── deploy-figorisk.sh         # Automated deployment script
└── README.md                  # Quick reference guide
```

***

## Quick Deployment

<Steps>
  <Step title="Download Package">
    Download and extract the deployment package:

    ```bash theme={null}
        wget https://releases.figorisk.com/figorisk-deployment-v1.0.0.zip
        unzip figorisk-deployment-v1.0.0.zip
        cd figorisk-deployment-package
    ```
  </Step>

  <Step title="Configure Environment">
    Copy the template and edit configuration:

    ```bash theme={null}
        cp .env.template .env
        nano .env
    ```

    **Required variables:**

    ```bash theme={null}
        # Database
        MONGO_URI=mongodb://admin:YOUR_PASSWORD@mongo:27017/figorisk?authSource=admin
        MONGO_ROOT_PASSWORD=YOUR_SECURE_PASSWORD
        
        # Security
        JWT_SECRET=$(openssl rand -hex 32)
        SUPER_ADMIN_PASSWORD=admin123
    ```

    See [Configuration Guide](/deployment/configuration) for all options.
  </Step>

  <Step title="Run Deployment Script">
    Execute the automated deployment:

    ```bash theme={null}
        chmod +x deploy-figorisk.sh
        ./deploy-figorisk.sh
    ```

    The script will:

    * ✅ Pull latest Docker images
    * ✅ Start all services
    * ✅ Run health checks
    * ✅ Display access information
  </Step>

  <Step title="Verify Deployment">
    Check all services are running:

    ```bash theme={null}
        docker-compose ps
    ```

    Expected output:

    ```
        NAME                 STATUS              PORTS
        figorisk-backend     Up (healthy)        3000/tcp
        figorisk-frontend    Up                  3000/tcp
        figorisk-mongo       Up                  27017/tcp
        figorisk-nginx       Up                  0.0.0.0:80->80/tcp
    ```
  </Step>

  <Step title="Access Application">
    Open your browser to: **[http://localhost](http://localhost)**

    Default login:

    * Username: `admin`
    * Password: Value from `SUPER_ADMIN_PASSWORD`
  </Step>
</Steps>

***

## Manual Deployment

If you prefer manual control over the deployment process:

### 1. Configure Environment

```bash theme={null}
cp .env.template .env
# Edit .env with your values
```

### 2. Create Directories

```bash theme={null}
mkdir -p uploads ssl
```

### 3. Pull Images

```bash theme={null}
docker-compose pull
```

This downloads all required images:

* Backend API
* Frontend application
* MongoDB database
* Nginx reverse proxy

### 4. Start Services

```bash theme={null}
docker-compose up -d
```

The `-d` flag runs services in detached mode (background).

### 5. Monitor Startup

Watch the logs during startup:

```bash theme={null}
docker-compose logs -f
```

Press `Ctrl+C` to stop following logs.

### 6. Verify Health

```bash theme={null}
# Check all services
docker-compose ps

# Test backend health
curl http://localhost/api/health

# Test frontend
curl http://localhost
```

***

## Service Configuration

### docker-compose.yml

The deployment uses this service architecture:

```yaml theme={null}
services:
  backend:
    image: glendyxfigorisk/figorisk-core:latest
    # NestJS API server
    
  frontend:
    image: glendyxfigorisk/figorisk-fe:latest
    # Next.js web application
    
  nginx:
    image: nginx:alpine
    # Reverse proxy and load balancer
    
  mongo:
    image: mongo:6.0
    # Database server
```

### Service Details

<Tabs>
  <Tab title="Backend">
    **Image**: `glendyxfigorisk/figorisk-core:latest`\
    **Technology**: NestJS (Node.js)\
    **Internal Port**: 3000\
    **Health Check**: `/health` endpoint

    **Key Features:**

    * RESTful API
    * JWT authentication
    * Role-based access control
    * MongoDB integration
    * AWS S3 integration (optional)
  </Tab>

  <Tab title="Frontend">
    **Image**: `glendyxfigorisk/figorisk-fe:latest`\
    **Technology**: Next.js (React)\
    **Internal Port**: 3000

    **Key Features:**

    * Server-side rendering
    * Responsive design
    * Modern UI components
    * Real-time updates
  </Tab>

  <Tab title="Database">
    **Image**: `mongo:6.0`\
    **Type**: NoSQL document database\
    **Internal Port**: 27017\
    **Data Storage**: Docker volume (`mongo_data`)

    **Features:**

    * Automatic backups via volume
    * Authentication enabled
    * Optimized for GRC data models
  </Tab>

  <Tab title="Nginx">
    **Image**: `nginx:alpine`\
    **External Ports**: 80 (HTTP), 443 (HTTPS)

    **Configuration:**

    * Reverse proxy to backend/frontend
    * Request routing
    * Rate limiting
    * SSL termination (if configured)
    * Static file caching
  </Tab>
</Tabs>

***

## Management Commands

### Starting & Stopping

```bash theme={null}
# Start all services
docker-compose up -d

# Stop all services
docker-compose down

# Restart all services
docker-compose restart

# Restart specific service
docker-compose restart backend
```

### Viewing Logs

```bash theme={null}
# All services (follow mode)
docker-compose logs -f

# Specific service
docker-compose logs -f backend
docker-compose logs -f frontend

# Last 100 lines
docker-compose logs --tail=100

# Since specific time
docker-compose logs --since 30m
```

### Checking Status

```bash theme={null}
# Service status
docker-compose ps

# Resource usage
docker stats

# Detailed service info
docker-compose ps backend
```

### Updating

```bash theme={null}
# Pull latest images
docker-compose pull

# Recreate containers with new images
docker-compose up -d

# Or use the deployment script
./deploy-figorisk.sh
```

***

## Data Persistence

### MongoDB Data

Data is stored in a Docker volume:

```bash theme={null}
# List volumes
docker volume ls

# Inspect volume
docker volume inspect figorisk-deployment-package_mongo_data

# Backup database
docker exec figorisk-mongo mongodump \
  --out=/backup \
  --username=admin \
  --password=YOUR_PASSWORD \
  --authenticationDatabase=admin

# Copy backup to host
docker cp figorisk-mongo:/backup ./mongo-backup
```

### Upload Files

User-uploaded files are stored in `./uploads`:

```bash theme={null}
# Backup uploads
tar -czf uploads-backup.tar.gz uploads/

# Restore uploads
tar -xzf uploads-backup.tar.gz
```

***

## Scaling Services

### Horizontal Scaling

Scale specific services:

```bash theme={null}
# Scale backend to 3 instances
docker-compose up -d --scale backend=3

# Scale with load balancing
# (Requires nginx configuration update)
```

### Vertical Scaling

Adjust resource limits in `docker-compose.yml`:

```yaml theme={null}
services:
  backend:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4G
        reservations:
          cpus: '1'
          memory: 2G
```

***

## Security Best Practices

<AccordionGroup>
  <Accordion icon="lock" title="Change Default Passwords">
    ```bash theme={null}
        # Generate strong passwords
        openssl rand -base64 32
        
        # Update in .env:
        MONGO_ROOT_PASSWORD=<generated-password>
        JWT_SECRET=<generated-secret>
        SUPER_ADMIN_PASSWORD=<strong-password>
    ```
  </Accordion>

  <Accordion icon="network-wired" title="Network Isolation">
    Services communicate via internal Docker network. Only nginx exposes ports externally.

    ```bash theme={null}
        # Verify network isolation
        docker network inspect figorisk-deployment-package_figorisk-network
    ```
  </Accordion>

  <Accordion icon="certificate" title="Enable HTTPS">
    1. Obtain SSL certificate
    2. Place in `ssl/` directory:

    ```
           ssl/
           ├── certificate.crt
           └── private.key
    ```

    3. Update nginx configuration for SSL
    4. Restart: `docker-compose restart nginx`
  </Accordion>

  <Accordion icon="shield" title="Regular Updates">
    ```bash theme={null}
        # Check for updates weekly
        docker-compose pull
        
        # Apply updates
        docker-compose up -d
        
        # Verify health
        docker-compose ps
    ```
  </Accordion>
</AccordionGroup>

***

## Troubleshooting

<AccordionGroup>
  <Accordion icon="circle-xmark" title="Container won't start">
    **Check logs:**

    ```bash theme={null}
        docker-compose logs <service-name>
    ```

    **Common causes:**

    * Port already in use
    * Missing environment variables
    * Insufficient resources
  </Accordion>

  <Accordion icon="database" title="Database connection errors">
    **Verify MongoDB is running:**

    ```bash theme={null}
        docker-compose ps mongo
        docker-compose logs mongo
    ```

    **Test connection:**

    ```bash theme={null}
        docker exec -it figorisk-mongo mongosh \
          --username admin \
          --password YOUR_PASSWORD \
          --authenticationDatabase admin
    ```
  </Accordion>

  <Accordion icon="network-wired" title="502 Bad Gateway">
    **Check backend health:**

    ```bash theme={null}
        docker-compose logs backend
        curl http://localhost/api/health
    ```

    **Restart services:**

    ```bash theme={null}
        docker-compose restart backend nginx
    ```
  </Accordion>

  <Accordion icon="hard-drive" title="Disk space issues">
    **Clean up unused resources:**

    ```bash theme={null}
        # Remove stopped containers
        docker container prune
        
        # Remove unused images
        docker image prune -a
        
        # Remove unused volumes (CAUTION: loses data)
        docker volume prune
    ```
  </Accordion>
</AccordionGroup>

***

## Performance Tuning

### MongoDB Optimization

```bash theme={null}
# Increase connection pool in .env
MONGO_URI=mongodb://admin:pass@mongo:27017/figorisk?authSource=admin&maxPoolSize=50
```

### Backend Optimization

```yaml theme={null}
# In docker-compose.yml
backend:
  environment:
    - NODE_ENV=production
    - NODE_OPTIONS=--max-old-space-size=4096
```

### Nginx Caching

Already configured in `nginx.conf`:

* Static assets cached for 1 year
* API responses not cached
* Compression enabled

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Configuration Options" icon="gear" href="/deployment/configuration">
    Explore all environment variables
  </Card>

  <Card title="Troubleshooting Guide" icon="wrench" href="/deployment/troubleshooting">
    Common issues and solutions
  </Card>

  <Card title="Backup & Restore" icon="floppy-disk" href="/guides/backup-restore">
    Data backup strategies
  </Card>

  <Card title="Monitoring" icon="chart-line" href="/guides/monitoring">
    Set up monitoring and alerts
  </Card>
</CardGroup>
