Build Your Own Private Cloud with Nextcloud on a Raspberry Pi

Take back your files

Google Drive, Dropbox, iCloud — they’re convenient, but you’re paying for storage you don’t control, handing your files to a third party, and subject to whatever pricing changes they fancy imposing next year. Nextcloud on a Raspberry Pi gives you a proper self-hosted alternative: your files, on your hardware, accessible from anywhere.

Nextcloud is a full-featured platform — file sync, photo library, calendar, contacts, notes, and more — all running locally. It has mobile apps for iOS and Android that work just like any cloud storage app, and a web interface for browser access. The difference is that the data never leaves your home.

What you’ll need

  • A Raspberry Pi 4 with at least 4GB of RAM (2GB will work but will feel tight)
  • External storage — an SSD via USB is ideal; a large SD card works but will wear out faster
  • Docker and Docker Compose installed on the Pi

Why Docker?

Nextcloud has a few moving parts — the application itself, a database, and ideally a reverse proxy. Running it all natively is doable but messy. Docker Compose keeps everything clean and makes updates trivially easy.

Setting up with Docker Compose

Create a directory for your Nextcloud setup and a docker-compose.yml file:

version: '3'

services:
  nextcloud:
    image: nextcloud:latest
    restart: unless-stopped
    ports:
      - 8080:80
    volumes:
      - /mnt/data/nextcloud:/var/www/html
    environment:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=yourpassword
    depends_on:
      - db

  db:
    image: mariadb:10.11
    restart: unless-stopped
    volumes:
      - /mnt/data/nextcloud-db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=yourrootpassword
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=yourpassword

Adjust the volume paths to point at wherever your external storage is mounted, then bring it up:

docker compose up -d

Browse to http://<your-pi-ip>:8080 and run through the Nextcloud setup wizard. That’s it — you now have a running Nextcloud instance.

Making it accessible remotely

For access from outside your home network, the cleanest approach is a Cloudflare Tunnel. It exposes your local Nextcloud to the internet via a proper domain name, with HTTPS handled automatically, and without requiring you to open any ports on your router. If you’re also running WireGuard from last week’s post, you can skip the tunnel entirely and just access Nextcloud through the VPN.

Mobile sync

Install the Nextcloud app on your phone and point it at your instance. It supports automatic photo and video upload — a direct replacement for Google Photos backup — as well as file sync for any folders you choose. The desktop clients for Windows, Mac, and Linux work exactly the same way.

A note on performance

Nextcloud on a Pi 4 is perfectly usable for personal and small family use. Large file transfers are fast; the web interface is snappy enough. Where it will feel sluggish is if you install every available Nextcloud app — keep it lean and it runs well. Don’t bother trying this on a Pi 3 or older for anything beyond light use.

Storage planning

The Pi’s SD card is not a good place to store your actual data. Use it only for the OS and Docker itself. Mount an external SSD via USB 3.0 and point your Nextcloud volumes there. An SSD is far more reliable for continuous read/write than a spinning drive or SD card, and USB 3.0 on the Pi 4 means you won’t be bottlenecked by the interface.

This is part three of our “Things to do with your old Raspberry Pi” series. Next week: monitoring your self-hosted services with Uptime Kuma.


Leave a Reply