Files
digiserver-v2/old_code_documentation/DOCKER.md

5.3 KiB

Docker Deployment Guide

Overview

DigiServer v2 Docker image features:

  • Base image size: ~400MB (optimized)
  • Full HD media support: Images, videos, PDFs
  • Optional LibreOffice: Install on-demand for PPTX support (+500MB)
  • Auto-initialization: Database and admin user created on first run
  • Non-root user: Runs as appuser (UID 1000) for security

Quick Start

1. Build and Run with Docker Compose

# Build the Docker image
docker-compose build

# Start the container
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the container
docker-compose down

The application will be available at http://localhost:5000

Default credentials:

  • Username: admin
  • Password: admin123

2. Build Docker Image Only

# Build the image
docker build -t digiserver-v2:latest .

# Run the container
docker run -d \
  -p 5000:5000 \
  -v $(pwd)/instance:/app/instance \
  -v $(pwd)/app/static/uploads:/app/app/static/uploads \
  --name digiserver \
  digiserver-v2:latest

Configuration

Environment Variables

Create a .env file based on .env.example:

cp .env.example .env

Edit the .env file to set your configuration:

  • SECRET_KEY: Change to a random secret key
  • FLASK_ENV: Set to production for production deployments

Persistent Data

The following directories are mounted as volumes:

  • ./instance: Database storage
  • ./app/static/uploads: Uploaded media files

These persist even when containers are recreated.

Production Deployment

# Create .env file with production settings
cp .env.example .env
nano .env  # Edit with your settings

# Start in production mode
docker-compose up -d

2. Behind a Reverse Proxy (Nginx/Traefik)

Example Nginx configuration:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # For large file uploads
        client_max_body_size 100M;
    }
}

3. Enable Redis Caching (Optional)

Uncomment the Redis service in docker-compose.yml:

  redis:
    image: redis:7-alpine
    container_name: digiserver-redis
    restart: unless-stopped
    volumes:
      - redis-data:/data

volumes:
  redis-data:

Update .env:

REDIS_URL=redis://redis:6379/0

Backup

Database Backup

# Backup database
docker exec digiserver tar -czf /tmp/backup.tar.gz /app/instance
docker cp digiserver:/tmp/backup.tar.gz ./backup-$(date +%Y%m%d).tar.gz

Full Backup (Database + Uploads)

# Backup everything
tar -czf digiserver-backup-$(date +%Y%m%d).tar.gz instance/ app/static/uploads/

Maintenance

View Logs

# All logs
docker-compose logs -f

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

# Specific service
docker-compose logs -f digiserver

Update Application

# Pull latest code
git pull

# Rebuild and restart
docker-compose down
docker-compose build
docker-compose up -d

Shell Access

# Access container shell
docker-compose exec digiserver bash

# Or with docker directly
docker exec -it digiserver bash

Installing Optional Dependencies

LibreOffice for PowerPoint Support:

# Method 1: Via Web UI (Recommended)
# Navigate to Admin Panel → System Dependencies
# Click "Install LibreOffice" button

# Method 2: Via Docker exec
docker exec -it digiserver bash
sudo /app/install_libreoffice.sh
exit

# Verify installation
docker exec digiserver libreoffice --version

Troubleshooting

Port Already in Use

Change the port mapping in docker-compose.yml:

ports:
  - "8080:5000"  # Change 8080 to your desired port

Permission Issues

Ensure the volumes have correct permissions:

sudo chown -R 1000:1000 instance/ app/static/uploads/

Container Won't Start

Check logs:

docker-compose logs digiserver

Reset Database

# Stop containers
docker-compose down

# Remove database
rm instance/*.db

# Start fresh
docker-compose up -d

System Requirements

Base Image

  • Docker 20.10+
  • Docker Compose 2.0+
  • 1GB RAM minimum (2GB recommended)
  • 5GB disk space (base + uploads)

With LibreOffice (Optional)

  • 2GB RAM recommended
  • 10GB disk space (includes LibreOffice + media)

Security Recommendations

  1. Change default credentials immediately after first login
  2. Set a strong SECRET_KEY in .env
  3. Use HTTPS with a reverse proxy in production
  4. Regular backups of database and uploads
  5. Update regularly to get security patches
  6. Restrict network access using firewall rules
  7. Monitor logs for suspicious activity

Performance Tuning

Adjust Workers

Edit Dockerfile CMD line:

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "8", "--timeout", "120", "app.app:create_app()"]

Resource Limits

Add to docker-compose.yml:

services:
  digiserver:
    # ... existing config ...
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
        reservations:
          cpus: '1'
          memory: 1G