Skip to content
GEEKnodes

Raspberry Pi

Nextcloud on Raspberry Pi: Your Private Cloud With Docker

Set up Nextcloud on a Raspberry Pi with Docker Compose: database, cache, data on SSD, background jobs, secure remote access and backups.

Nextcloud is a private cloud you install on your own hardware: it syncs files, uploads phone photos and keeps contacts and calendars, like Google Drive or iCloud, but with the data at home. A Raspberry Pi 4 or 5 is enough for a family. In this guide we set it up with Docker Compose, step by step.

In short

  • Use a Raspberry Pi 4 or 5 with 4 GB or more and 64-bit Raspberry Pi OS.
  • Keep the data on an SSD, not on the SD card.
  • With Docker Compose you run three pieces: Nextcloud, a MariaDB database and a Redis cache.
  • Schedule background jobs with cron so everything runs smoothly.
  • For remote access, a VPN beats opening ports on the router.

What you need

Why not the SD card? Nextcloud writes constantly to the database and logs. An SD card wears out and is also slow with many small files.

How the pieces fit

Nextcloud is not a single program. It needs a database for users, permissions and file indexes, and benefits a lot from an in-memory cache. With Docker, each piece runs in its own container:

ContainerImagePurpose
appnextcloudThe web app and the API the apps use
dbmariadbDatabase with users, files and settings
redisredisCache and file locking, more speed

All three official images have an arm64 version, so they run on the Raspberry Pi without tricks.

Phone, laptop and browser connect through port 8080 to the application container, which uses the database, the cache and an SSD with the data
Three containers on the Pi and data on an SSD; devices come in through a single port.

Step 1: prepare the folder

Create a folder for the service. If the system does not boot from the SSD, mount the drive first and create the folder on it.

mkdir -p ~/docker/nextcloud && cd ~/docker/nextcloud
nano compose.yaml

Step 2: the compose.yaml file

Paste this content and change both passwords to long, different ones:

services:
  db:
    image: mariadb:lts
    container_name: nextcloud-db
    command: --transaction-isolation=READ-COMMITTED
    environment:
      - MYSQL_ROOT_PASSWORD=change-this-root-password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=change-this-password
    volumes:
      - ./db:/var/lib/mysql
    restart: unless-stopped

  redis:
    image: redis:alpine
    container_name: nextcloud-redis
    restart: unless-stopped

  app:
    image: nextcloud:stable
    container_name: nextcloud
    ports:
      - "8080:80"
    environment:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=change-this-password
      - REDIS_HOST=redis
    volumes:
      - ./html:/var/www/html
    depends_on:
      - db
      - redis
    restart: unless-stopped

The stable tag follows the latest version considered stable. The ./html folder holds the program, configuration and your files; ./db, the database.

Step 3: start and create the administrator

Start the three containers:

docker compose up -d

The first time takes a few minutes. Then:

  1. Open http://YOUR-PI-IP:8080 in your browser.
  2. Create the administrator account with a strong password.
  3. Accept or skip the recommended apps (calendar, contacts…). You can install them later.
  4. Go to Administration settings → Overview and check the warnings.

If you see “Access through untrusted domain” when using another name or IP, add it to the trusted domains list:

docker exec -u www-data nextcloud php occ config:system:set trusted_domains 1 --value=192.168.1.10

occ is Nextcloud’s command line tool. It always runs as user www-data.

Step 4: background jobs with cron

Nextcloud runs periodic tasks: emptying the trash, generating thumbnails, sending notifications. By default it triggers them when pages load (AJAX mode), which is slow. The recommendation is cron.

In Administration settings → Basic settings, select Cron. Then on the Pi, open your user’s crontab:

crontab -e

And add this line to run it every 5 minutes:

*/5 * * * * docker exec -u www-data nextcloud php -f /var/www/html/cron.php

If you do not know cron, here is how to schedule tasks on Raspberry Pi.

Step 5: install the apps on your devices

Nextcloud has official clients for almost everything:

  • Windows, macOS and Linux: the desktop client syncs a folder, like Dropbox.
  • Android and iOS: the app uploads your camera roll automatically.
  • Contacts and calendars: sync via CardDAV and CalDAV with the phone’s native apps.

When adding the account, type the full address with the port: http://192.168.1.10:8080.

Comparison between a public cloud, with a monthly fee and data on third-party servers, and a private cloud at home, with your data and your own maintenance
Private cloud: the data is yours, and so is the maintenance.

How do I access it from outside home?

This is the most important security decision. You have two routes:

OptionProsCons
VPN (Tailscale or WireGuard)Nothing opened on the router; Nextcloud is not exposed to the internetEach device needs the VPN app
Open port + domain + HTTPSAccess from any browserExposed to attacks; requires reverse proxy, certificates and strict updating

To start, use a VPN. With Tailscale on Raspberry Pi you open no ports, and with WireGuard and PiVPN you control everything yourself.

If you want to publish it later, first read how to open ports on your router and how HTTPS works. Never expose it over unencrypted HTTP.

Maintenance: update without scares

To update, inside the service folder:

docker compose pull
docker compose up -d

Nextcloud does not allow skipping major versions: going from 30 to 32 requires passing through 31. With the stable tag and frequent updates you will have no trouble. If an update stalls, check the logs with docker compose logs app.

Backups

A private cloud is not a backup: if the SSD fails, you lose everything. Follow the 3-2-1 rule:

  1. Three copies of important data (the original plus two).
  2. On two media, for example the SSD and a USB drive.
  3. One off-site, at a relative’s house or in an encrypted service.

To back up, enable maintenance mode, copy the folder and disable it:

docker exec -u www-data nextcloud php occ maintenance:mode --on
sudo rsync -a ~/docker/nextcloud/ /mnt/backup/nextcloud/
docker exec -u www-data nextcloud php occ maintenance:mode --off

If you want a dedicated backup drive, see how to turn a Raspberry Pi into a home NAS.

3-2-1 backup rule: three copies, on two different media and one of them off-site
The 3-2-1 rule: three copies, two media, one off-site.

Frequently asked questions

What is Nextcloud All-in-One and why do we not use it here? It is an official installer that manages all containers itself, backups included. It is very good, but it is meant to be used with a public domain and HTTPS. For a cloud only reachable at home or via VPN, this guide’s compose.yaml is easier to understand.

How many users can a Raspberry Pi handle? It works well for a family or small group. The heaviest part is the first upload of thousands of photos and thumbnail generation; afterwards daily use is light.

Can I store files on a large USB drive? Yes. Mount the drive at a fixed path and create the service folder on it, or change the ./html volume to a path on the drive. Format it as ext4: NTFS and exFAT cause permission problems.

Does it replace Google Photos? For storing phone photos, yes. There are extra apps for face recognition and advanced search, but they run slowly on a Raspberry Pi.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor