# Nextcloud Full Stack

> Nextcloud with PostgreSQL, Redis, and Collabora Office.

- Category: Storage & Backup
- Difficulty: intermediate
- Components: nextcloud, postgresql, redis, collabora
- Tags: nextcloud, cloud, file-sync, collaboration, office
- Source: https://docker.recipes/storage/nextcloud-full

## Overview

Nextcloud is an open-source, self-hosted productivity platform that serves as a complete alternative to commercial cloud services like Google Workspace or Microsoft 365. Originally forked from ownCloud in 2016, Nextcloud has evolved into a comprehensive collaboration suite offering file synchronization, sharing, calendar, contacts, video calls, and document editing capabilities. With over 200 available apps and strong privacy controls, it enables organizations to maintain complete control over their data while providing modern cloud functionality.

This full-stack deployment combines Nextcloud with PostgreSQL for robust data storage, Redis for high-performance caching and session management, and Collabora Office for real-time collaborative document editing. PostgreSQL provides ACID-compliant data integrity and advanced querying capabilities essential for Nextcloud's complex metadata and sharing permissions. Redis dramatically improves performance by caching frequently accessed data and managing user sessions in memory, while Collabora Office transforms Nextcloud into a complete office suite with LibreOffice-powered online editing.

This configuration is ideal for organizations seeking a privacy-focused alternative to commercial cloud platforms, educational institutions requiring collaborative tools without vendor lock-in, and teams needing enterprise-grade file sharing with integrated office capabilities. The combination delivers sub-second file access through Redis caching, reliable data storage via PostgreSQL's proven architecture, and professional document collaboration through Collabora's LibreOffice integration.

## Features

- Real-time collaborative document editing with LibreOffice Online through Collabora Office
- Sub-millisecond file access and session management via Redis in-memory caching
- ACID-compliant data storage with PostgreSQL's advanced transaction support
- Cross-device file synchronization with conflict resolution and version history
- Comprehensive sharing controls with password protection, expiration dates, and permission levels
- Integrated CalDAV and CardDAV servers for calendar and contact synchronization
- End-to-end encryption for sensitive files with client-side key management
- Extensive app ecosystem with over 200 plugins for mail, chat, project management, and more

## Use cases

- Small businesses replacing Google Workspace or Office 365 with self-hosted alternative
- Educational institutions providing students and faculty with collaborative document editing
- Healthcare organizations requiring HIPAA-compliant file sharing and storage
- Remote teams needing centralized file access with real-time document collaboration
- Government agencies implementing privacy-focused cloud storage with data sovereignty
- Creative agencies sharing large media files with clients through branded portals
- Home labs and personal clouds for family file sharing and photo backup

## Prerequisites

- Minimum 3GB RAM (1GB+ for PostgreSQL, 512MB+ for Redis, 2GB+ for Nextcloud with Collabora)
- 20GB+ available disk space for application data and user files
- Ports 8080 (Nextcloud) and 9980 (Collabora) available on the host system
- Basic understanding of Nextcloud administration and app installation
- Domain name or reverse proxy setup for production SSL/TLS termination
- Firewall configuration allowing HTTP/HTTPS traffic for external access

## docker-compose.yml

```yaml
services:
  postgres:
    image: postgres:16-alpine
    container_name: nextcloud-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-nextcloud}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud}
      POSTGRES_DB: ${POSTGRES_DB:-nextcloud}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - nextcloud-network

  redis:
    image: redis:alpine
    container_name: nextcloud-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - nextcloud-network

  nextcloud:
    image: nextcloud:latest
    container_name: nextcloud
    restart: unless-stopped
    ports:
      - "${NEXTCLOUD_PORT:-8080}:80"
    environment:
      - POSTGRES_HOST=postgres
      - POSTGRES_DB=${POSTGRES_DB:-nextcloud}
      - POSTGRES_USER=${POSTGRES_USER:-nextcloud}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-nextcloud}
      - REDIS_HOST=redis
      - NEXTCLOUD_ADMIN_USER=${ADMIN_USER:-admin}
      - NEXTCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
      - NEXTCLOUD_TRUSTED_DOMAINS=${TRUSTED_DOMAINS:-localhost}
    volumes:
      - nextcloud_data:/var/www/html
    depends_on:
      - postgres
      - redis
    networks:
      - nextcloud-network

  collabora:
    image: collabora/code:latest
    container_name: collabora
    restart: unless-stopped
    ports:
      - "${COLLABORA_PORT:-9980}:9980"
    environment:
      - domain=${NEXTCLOUD_DOMAIN:-localhost}
      - extra_params=--o:ssl.enable=false
    cap_add:
      - MKNOD
    networks:
      - nextcloud-network

volumes:
  postgres_data:
  redis_data:
  nextcloud_data:

networks:
  nextcloud-network:
    driver: bridge
```

## .env

```bash
# Nextcloud Full Stack
NEXTCLOUD_PORT=8080
COLLABORA_PORT=9980
POSTGRES_USER=nextcloud
POSTGRES_PASSWORD=nextcloud
POSTGRES_DB=nextcloud
ADMIN_USER=admin
ADMIN_PASSWORD=admin
TRUSTED_DOMAINS=localhost
NEXTCLOUD_DOMAIN=localhost
```

## Usage notes

- Nextcloud at http://localhost:8080
- Collabora at http://localhost:9980
- Install Collabora app in Nextcloud
- Edit Office docs in browser

## Troubleshooting

- Collabora connection failed: Ensure NEXTCLOUD_DOMAIN environment variable matches your actual domain and install the Collabora Online app in Nextcloud admin panel
- Database connection errors: Verify POSTGRES_PASSWORD matches between postgres and nextcloud services, and ensure PostgreSQL container is fully started before Nextcloud
- Redis cache not working: Check Redis container logs for memory issues and ensure REDIS_HOST environment variable points to the correct service name
- File uploads failing: Increase PHP memory limits and upload size in Nextcloud config.php or add custom php.ini volume mount
- Trusted domain warnings: Add your domain/IP to NEXTCLOUD_TRUSTED_DOMAINS environment variable or configure through admin interface
- Collabora documents won't open: Verify domain configuration in Collabora settings matches NEXTCLOUD_DOMAIN and check that both services can communicate on the Docker network

