How to Install Nextcloud on a VPS with Docker

Nextcloud is a self-hosted file sync, sharing, and collaboration platform — a privacy-focused alternative to Google Drive or Dropbox where you control the data entirely.

Prerequisites

  • Docker Engine and Docker Compose installed
  • A domain name pointing to your VPS
  • At least 2 vCPU, 4 GB RAM recommended

Step 1 — Create a Project Directory

mkdir ~/nextcloud && cd ~/nextcloud

Step 2 — Create docker-compose.yml

services:
  db:
    image: mariadb:10.11
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql

  redis:
    image: redis:7
    restart: unless-stopped

  app:
    image: nextcloud:latest
    restart: unless-stopped
    ports:
      - "8080:80"
    depends_on:
      - db
      - redis
    environment:
      MYSQL_HOST: db
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: ${DB_PASSWORD}
      REDIS_HOST: redis
      NEXTCLOUD_TRUSTED_DOMAINS: yourdomain.com
    volumes:
      - nextcloud_data:/var/www/html

volumes:
  db_data:
  nextcloud_data:

Step 3 — Create a .env File

DB_ROOT_PASSWORD=change_me_strong_password
DB_PASSWORD=change_me_another_strong_password

Step 4 — Start the Stack

docker compose up -d

Step 5 — Complete Setup in the Browser

http://YOUR_SERVER_IP:8080

Create your administrator account when prompted.

Step 6 — Add HTTPS via Nginx Proxy Manager

See How to Install Nginx Proxy Manager with Docker to route yourdomain.com to port 8080 with free SSL.

Step 7 — Configure Redis Caching (Improves Performance)

Already included in the compose file above — verify it's active in Nextcloud's admin settings under Overview.

Setting Storage Limits Per User

Configure in the admin panel under Settings → Users, setting a quota per account.

Enabling Background Jobs (Cron)

Set Nextcloud's background job method to Cron in Settings → Basic Settings, then schedule it:

*/5 * * * * docker exec -u www-data nextcloud-app-1 php cron.php

Backing Up Nextcloud

docker exec nextcloud-db-1 mysqldump -u root -pYOUR_ROOT_PASSWORD nextcloud > nextcloud-db-backup.sql
docker run --rm -v nextcloud_nextcloud_data:/data -v $(pwd):/backup alpine tar czf /backup/nextcloud-files-backup.tar.gz /data

Common Errors

"Access through untrusted domain" — add your domain to NEXTCLOUD_TRUSTED_DOMAINS and restart the container.

Slow performance with many files — confirm Redis caching is active, and consider increasing PHP memory limits within the container.

Best Practices

  • Always run behind HTTPS in production
  • Enable Redis for meaningfully better performance
  • Set up regular automated backups of both database and file volumes

Continue Reading

Browse more articles in Popular Self-Hosted Applications.

  • nextcloud, self hosted cloud storage, nextcloud docker, google drive alternative
  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

How to Install GitLab CE on a VPS

GitLab Community Edition is a full-featured, self-hosted DevOps platform — Git repository...

How to Install Ghost CMS on a VPS

Ghost is a modern, fast, purpose-built platform for blogging and newsletters — a lighter,...

How to Set Up a Minecraft Server on a VPS

Running your own Minecraft server gives you full control over mods, plugins, and world settings....

How to Install n8n for Workflow Automation

n8n is a self-hosted workflow automation tool — connecting apps and APIs through a visual...

How to Install Gitea (Lightweight Git Server)

Gitea is a lightweight, self-hosted Git service — a much lower-resource alternative to...