Skip to content

Nextcloud SetupΒΆ

Self-hosted productivity platform with file sync & share, calendars, contacts and more.

πŸ› οΈ Service ConfigurationΒΆ

Core ServicesΒΆ

nextcloud-postgres:
  image: postgres:latest
  container_name: nextcloud-postgres
  hostname: nextcloud-postgres
  restart: always
  <<: *resource-limits
  logging:
    <<: *default-logging
    options:
      <<: *default-logging-options
      loki-external-labels: job=nextcloud-postgres
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
    interval: 10s
    timeout: 5s
    retries: 5
  environment:
    POSTGRES_USER: ${POSTGRES_USER:-nextcloud} # (1)
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} # (2)
    POSTGRES_DB: ${POSTGRES_DB:-nextcloud} # (3)
    UID: ${UID_NAS_ADMIN:-1026} # optional (4)
    GID: ${GID_NAS_ADMIN:-100} # optional (5)
  volumes:
    - type: bind
      source: /etc/localtime
      target: /etc/localtime
      read_only: true
    - type: bind
      source: ${MOUNT_PATH_DOCKER_ROOT:?path required}/nextcloud/db
      target: /var/lib/postgresql/data
  labels:
    <<: *default-labels
    monitoring: nextcloud-postgress
  networks:
    dockerization:
  1. β†’ Database username (default: nextcloud)
  2. β†’ Database password (default: nextcloud)
  3. β†’ Database name (default: nextcloud)
  4. β†’ Optional user ID for volume permissions (default: 1026)
  5. β†’ Optional group ID for volume permissions (default: 100)
nextcloud-redis:
  image: redis:alpine
  container_name: nextcloud-redis
  hostname: nextcloud-redis
  restart: always
  <<: *resource-limits
  logging:
    <<: *default-logging
    options:
      <<: *default-logging-options
      loki-external-labels: job=nextcloud-redis
  healthcheck:
    test: ["CMD", "redis-cli", "ping"]
    interval: 10s
    timeout: 5s
    retries: 5
  networks:
    dockerization:
  environment:
    UID: ${UID_NAS_ADMIN:-1026} # optional (1)
    GID: ${GID_NAS_ADMIN:-100} # optional (2)
  volumes:
    - type: bind
      source: /etc/localtime
      target: /etc/localtime
      read_only: true
  labels:
    <<: *default-labels
    monitoring: nextcloud-redis
  1. β†’ Optional user ID for volume permissions (default: 1026)
  2. β†’ Optional group ID for volume permissions (default: 100)
nextcloud:
  image: nextcloud:latest
  container_name: nextcloud
  hostname: nextcloud
  restart: always
  <<: *resource-limits
  logging:
    <<: *default-logging
    options:
      <<: *default-logging-options
      loki-external-labels: job=nextcloud
  healthcheck:
    test: ["CMD-SHELL", "curl --fail http://localhost:80 || exit 1"]
    interval: 60s
    retries: 5
    start_period: 20s
    timeout: 10s
  ports:
    - "${NEXT_CLOUD_PORT:-81}:80"
  volumes:
    - type: bind
      source: /etc/localtime
      target: /etc/localtime
      read_only: true
    - type: bind
      source: ${MOUNT_PATH_DOCKER_ROOT}/nextcloud/app
      target: /var/www/html
  environment:
    POSTGRES_USER: ${POSTGRES_USER:-nextcloud} # (1)
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} # (2)
    POSTGRES_DB: ${POSTGRES_DB:-nextcloud} # (3)
    POSTGRES_HOST: ${POSTGRES_HOST:-nextcloud-postgres} # (4)
    NEXTCLOUD_DATADIR: /mnt/ncdata # (5)
    NEXTCLOUD_UPLOAD_LIMIT: 10G # (6)
    NEXTCLOUD_MEMORY_LIMIT: 512M # (7)
    TRUSTED_DOMAINS: nextcloud.${SYNOLOGY_BASIC_URL:?Synology URL required} # (8)
    SMTP_HOST: ${SMTP_HOST:-smtp.mail.me.com} # (9)
    SMTP_SECURE_MODE: tls # (10)
    SMTP_PORT: ${SMTP_PORT:-587} # (11)
    SMTP_NAME: ${EMAIL} # (12)
    SMTP_PASSWORD: ${SMTP_PASSWORD} # (13)
    UID: ${UID_NAS_ADMIN:-1026} # optional (14)
    GID: ${GID_NAS_ADMIN:-100} # optional (15)
  depends_on:
    nextcloud-postgres:
      condition: service_healthy
    nextcloud-redis:
      condition: service_healthy
  labels:
    <<: *default-labels
    monitoring: nextcloud
  networks:
    dockerization:
  1. β†’ PostgreSQL username (matches database service)
  2. β†’ PostgreSQL password (matches database service)
  3. β†’ Database name (matches database service)
  4. β†’ Database hostname (using Docker service name)
  5. β†’ Data storage path inside container
  6. β†’ Max upload size (10GB)
  7. β†’ PHP memory limit (512MB)
  8. β†’ Trusted domain (required)
  9. β†’ SMTP server for email
  10. β†’ SMTP encryption (TLS)
  11. β†’ SMTP port (587)
  12. β†’ Email address for SMTP auth
  13. β†’ SMTP password (must be set in .env)
  14. β†’ User ID for volume permissions (default: 1026)
  15. β†’ Group ID for volume permissions (default: 100)

πŸ” Required Environment VariablesΒΆ

Refer to Environment Variables documentation for:

Variable Description Required
MOUNT_PATH_DOCKER_ROOT Storage path βœ…
SYNOLOGY_BASIC_URL Domain for trusted hosts βœ…
EMAIL Admin email for SMTP βœ…
SMTP_PASSWORD SMTP auth password βœ…
UID_NAS_ADMIN User ID for volume permissions ⚠️ Recommended
GID_NAS_ADMIN Group ID for volume permissions ⚠️ Recommended

Security Notice

  • Be stored in .env files
  • Have restricted permissions (chmod 600)
  • Never be committed to version control
  • Be rotated periodically

πŸš€ DeploymentΒΆ

  1. Create .env file with required variables
  2. Initialize volumes
    mkdir -p ${MOUNT_PATH_DOCKER_ROOT}/nextcloud/{db,app}
    chown -R ${UID_NAS_ADMIN:-1026}:${GID_NAS_ADMIN:-100} ${MOUNT_PATH_DOCKER_ROOT}/nextcloud
    
  3. Start services
    docker-compose up -d
    
  4. Access web UI at http://yourdomain.com:81

πŸ”„ MaintenanceΒΆ

  • Backups
    • Regularly backup both the PostgreSQL and app volumes
  • Updates
    docker-compose pull && docker-compose up -d
    
  • Logs
    docker-compose logs -f