Docker Deployment Guide

Deploy AuthentiVoice using Docker for a consistent, reproducible deployment across any environment.

Prerequisites

Docker Engine

Docker version 20.10 or higher

Docker Compose

Docker Compose v2.0 or higher

Resources

4GB RAM, 2 CPU cores minimum

Storage

20GB available disk space

Quick Start

1

Clone Repository

git clone https://github.com/your-org/authentivoice.git
cd authentivoice
2

Configure Environment

# Copy example environment file
cp .env.example .env

# Edit configuration
nano .env
3

Build Images

# Build all services
make build-all

# Or build individually
make build-frontend
make build-backend
4

Start Services

# Start all services
docker-compose up -d

# Check status
docker-compose ps

Docker Architecture

Service Overview

services:
  frontend:
    image: authentivoice/frontend:latest
    ports:
      - "80:80"
    environment:
      - VITE_API_BASE_URL=http://backend:8000
    depends_on:
      - backend

  backend:
    image: authentivoice/backend:latest
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/authentivoice
    depends_on:
      - db
      - redis

  db:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=authentivoice
      - POSTGRES_USER=authentivoice
      - POSTGRES_PASSWORD=secure_password

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data

Frontend Container

Dockerfile Configuration

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --legacy-peer-deps
COPY . .
ARG VITE_SUPABASE_URL
ARG VITE_SUPABASE_ANON_KEY
ARG VITE_API_BASE_URL
RUN npm run build

# Production stage
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

Frontend Environment Variables

Backend Container

Multi-Stage Backend Build

# Base stage with common dependencies
FROM python:3.11-slim AS base
WORKDIR /app
RUN apt-get update && apt-get install -y \
    ffmpeg \
    git \
    && rm -rf /var/lib/apt/lists/*

# Dependencies stage
FROM base AS dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Application stage
FROM dependencies AS app
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

Backend Environment Variables

Docker Compose Configuration

Complete docker-compose.yml

version: '3.8'

services:
  frontend:
    build:
      context: ./frontend
      args:
        - VITE_SUPABASE_URL=${VITE_SUPABASE_URL}
        - VITE_SUPABASE_ANON_KEY=${VITE_SUPABASE_ANON_KEY}
        - VITE_API_BASE_URL=${VITE_API_BASE_URL}
    image: authentivoice/frontend:${VERSION:-latest}
    ports:
      - "${FRONTEND_PORT:-80}:80"
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - authentivoice

  backend:
    build:
      context: ./backend
    image: authentivoice/backend:${VERSION:-latest}
    ports:
      - "${BACKEND_PORT:-8000}:8000"
    environment:
      - DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}
      - REDIS_URL=redis://redis:6379/0
      - S3_ENDPOINT=${S3_ENDPOINT}
      - S3_ACCESS_KEY=${S3_ACCESS_KEY}
      - S3_SECRET_KEY=${S3_SECRET_KEY}
      - S3_BUCKET=${S3_BUCKET}
      - GEMINI_API_KEY=${GEMINI_API_KEY}
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - authentivoice
    volumes:
      - ./backend/logs:/app/logs

  db:
    image: postgres:15-alpine
    environment:
      - POSTGRES_DB=${DB_NAME:-authentivoice}
      - POSTGRES_USER=${DB_USER:-authentivoice}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init-db:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-authentivoice}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - authentivoice

  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - authentivoice

volumes:
  postgres_data:
  redis_data:

networks:
  authentivoice:
    driver: bridge

Deployment Strategies

Development Environment

  • Local Development
  • Testing
# Start with hot reload
docker-compose -f docker-compose.dev.yml up

# View logs
docker-compose logs -f backend

# Access shell
docker-compose exec backend bash

Production Deployment

# Run as non-root user
RUN addgroup -g 1001 -S authentivoice && \
    adduser -S -u 1001 -G authentivoice authentivoice
USER authentivoice

# Security headers in nginx
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
services:
  backend:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4G
        reservations:
          cpus: '1'
          memory: 2G
services:
  backend:
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
        labels: "service=backend"
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
  interval: 30s
  timeout: 10s
  retries: 3
  start_period: 40s

Container Management

Common Operations

# Start all services
docker-compose up -d

# Start specific service
docker-compose up -d backend

# Scale service
docker-compose up -d --scale backend=3

Backup and Restore

1

Backup Database

# Backup PostgreSQL
docker-compose exec db pg_dump -U authentivoice authentivoice > backup.sql

# Backup with timestamp
docker-compose exec db pg_dump -U authentivoice authentivoice > backup_$(date +%Y%m%d_%H%M%S).sql
2

Backup Volumes

# Stop services
docker-compose stop

# Backup volumes
docker run --rm -v authentivoice_postgres_data:/data -v $(pwd):/backup alpine tar czf /backup/postgres_data.tar.gz -C /data .
3

Restore Database

# Restore PostgreSQL
docker-compose exec -T db psql -U authentivoice authentivoice < backup.sql

# Restore volumes
docker run --rm -v authentivoice_postgres_data:/data -v $(pwd):/backup alpine tar xzf /backup/postgres_data.tar.gz -C /data

Performance Optimization

Image Optimization

  • Separate build and runtime stages
  • Only include necessary files in final image
  • Use Alpine Linux for smaller images
  • Remove build dependencies
# Good: Dependencies change less frequently
COPY package*.json ./
RUN npm ci
COPY . .

# Bad: Invalidates cache on any file change
COPY . .
RUN npm ci
# Use buildkit for better caching
DOCKER_BUILDKIT=1 docker build .

# Cache mount for package managers
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install -r requirements.txt

Monitoring and Logging

Container Monitoring

# Add monitoring stack
services:
  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus
    ports:
      - "9090:9090"
    
  grafana:
    image: grafana/grafana:latest
    volumes:
      - grafana_data:/var/lib/grafana
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin

Log Aggregation

# Centralized logging
services:
  elasticsearch:
    image: elasticsearch:8.11.0
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
    volumes:
      - es_data:/usr/share/elasticsearch/data
      
  logstash:
    image: logstash:8.11.0
    volumes:
      - ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf
    depends_on:
      - elasticsearch
      
  kibana:
    image: kibana:8.11.0
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch

Troubleshooting

Check logs: docker-compose logs service_nameCommon issues:
  • Port already in use
  • Environment variables missing
  • Volume permissions
  • Health check failures
Monitor resources: docker statsSolutions:
  • Increase memory limits
  • Add more CPU allocation
  • Use volume mounts for databases
  • Enable swap accounting
Inspect network: docker network inspect authentivoice_defaultFixes:
  • Check firewall rules
  • Verify DNS resolution
  • Use custom networks
  • Check port bindings

Next Steps

1

Review Configuration

Ensure all environment variables are properly set
2

Test Deployment

Deploy to a staging environment first
3

Set Up Monitoring

Implement logging and monitoring solutions
4

Plan Scaling

Prepare for horizontal scaling as needed