GuidesFiles, photos and homeFiles with Nextcloud

Run Nextcloud with rootless Docker

Your own Nextcloud for files, calendars and contacts on Debian 13, in rootless Docker services under a user of its own, with HTTPS, background jobs, updates and backups.

Tested on Docker steps follow the tested rootless Docker base guide on Debian 13 with Docker Engine 29.10.1, Compose 5.8.1 and rootlesskit 3.3.0; the app version and app-specific behaviour are from the tested Podman guide on a Melonslab server. Not re-tested end to end under Docker. Updated November 28, 2026

Recommended server for this guide

VC-S Micro · 2 vCPU · 8 GB Memory · 250 GB Storage

Month to month, no lock-in 7-day money-back guarantee

These steps were tested on VC-P Alloy. VC-S Micro has the same number of vCPUs and memory on an older CPU, and 250 GB of storage instead of 60 GB, which matters more here.

€7.99/mo

Deploy now

Quick install on a fresh VM

This command sets up a rootless container engine and a directory for this service. Podman is the default; add --engine docker to the command to use Docker instead.

curl -fsSL https://www.melonslab.com/install/rootless.sh | bash -s -- --app nextcloud-docker --manifest nextcloud --sha256 71f2068126e64f39e66b616b69dda468294b262ca4d7e28e6db5a701e8fc441e
View the script

SHA-256: 97785be3e3e91393181a4a7caeab5f4b52803bf52e960dd488945cb38c6473a2

Run this guide on Melonslab

We ran every step below on our own server. For this workload we recommend VC-S Micro at €7.99/mo. Order it, pick Debian 13, and follow the guide.

  1. 1. Order the server. Use the button below to order the recommended plan. Choose Debian 13 when the installer asks for an operating system.
  2. 2. Add IPv4 if needed. Add it on the order form when the guide publishes a service on the internet. It is a paid add-on, not included in the plan.
  3. 3. Connect over SSH. Log in as root with the address and credentials from your order, then run the commands below.
  4. 4. Follow the verified steps. Every command in this guide was run on a Melonslab server before it was published.
Deploy now
On this page

What you will set up

The Docker steps below follow our tested rootless Docker guide. The app version and the app-specific results come from the tested Podman guide on a Melonslab server; they were not measured under Docker, and this app was not re-tested end to end with Docker.

Nextcloud keeps your files, calendars and contacts on your own server, and syncs them to your computers and phones. Here it runs as three containers in one Compose project, under a user of its own called nextcloud:

  • Nextcloud itself, with Apache and PHP,
  • MariaDB, its database,
  • Redis, for caching and file locking.

Caddy, set up in the Docker guide, handles HTTPS in front of it.

In the Podman test, on a fresh Melonslab VC-P Alloy (2 vCPU, 8 GB) with Debian 13: Nextcloud 34 was installed, then upgraded to 35. At idle, the containers used under 300 MB of memory. Files, calendar and contact access, HTTPS over IPv4 and IPv6, visitors' real IP addresses, background jobs, a reboot, and a backup restored into empty volumes were all checked.

Before you start

You need:

  • a server set up as in the Docker guide, with Caddy running;
  • a name for your Nextcloud, such as cloud.example.com, with an A record and an AAAA record pointing at your server.

The examples use cloud.example.com for the name and 203.0.113.10 for your server's IPv4 address. Replace them with your own throughout.

For Nextcloud, our Standard plans are usually the better fit: they have hard disks in RAID 10, from 250 GB on the smallest plan up to 1 TB, so there is room for files at a lower price. The Performance plans have faster SSD storage but less of it.

1. Create the user

As root:

useradd -m -s /bin/bash -U nextcloud
loginctl enable-linger nextcloud
uid=$(id -u nextcloud)

Steps 2 to 11 use the runuser commands shown below, as nextcloud, from /home/nextcloud/nextcloud.

2. Create the passwords

umask 077
mkdir -p /home/nextcloud/nextcloud
printf %s "MARIADB_PASSWORD=$(openssl rand -hex 24)" > /home/nextcloud/nextcloud/db.env
printf %s "MYSQL_PASSWORD=$(grep -o '[^=]*$' /home/nextcloud/nextcloud/db.env)" > /home/nextcloud/nextcloud/app-db.env
printf %s "NEXTCLOUD_ADMIN_PASSWORD=$(openssl rand -hex 16)" > /home/nextcloud/nextcloud/admin.env
chmod 600 /home/nextcloud/nextcloud/*.env
umask 022

Docker stores these as secrets and hands them to the containers when they start, so no password is written into the files below. printf %s keeps a line break out of the password.

3. Describe the Compose project

mkdir -p /home/nextcloud/nextcloud
chown -R nextcloud:nextcloud /home/nextcloud/nextcloud

Create /home/nextcloud/nextcloud/compose.yaml:

services:
  nextcloud-db:
    image: docker.io/library/mariadb:11.8
    env_file:
      - ./db.env
    environment:
      MARIADB_DATABASE: nextcloud
      MARIADB_USER: nextcloud
      MARIADB_RANDOM_ROOT_PASSWORD: "1"
      MARIADB_AUTO_UPGRADE: "1"
    command: --transaction-isolation=READ-COMMITTED
    volumes:
      - nextcloud-db:/var/lib/mysql
    restart: always

  nextcloud-redis:
    image: docker.io/library/redis:8-alpine
    restart: always

  nextcloud-app:
    image: docker.io/library/nextcloud:34-apache
    env_file:
      - ./app-db.env
      - ./admin.env
    environment:
      MYSQL_HOST: nextcloud-db
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      NEXTCLOUD_ADMIN_USER: admin
      NEXTCLOUD_TRUSTED_DOMAINS: cloud.example.com
      OVERWRITEPROTOCOL: https
      OVERWRITECLIURL: https://cloud.example.com
      TRUSTED_PROXIES: 203.0.113.10
      REDIS_HOST: nextcloud-redis
    extra_hosts:
      - "cloud.example.com:host-gateway"
    ports:
      - "127.0.0.1:8081:80"
    volumes:
      - nextcloud:/var/www/html
    depends_on:
      - nextcloud-db
      - nextcloud-redis
    restart: always

volumes:
  nextcloud-db:
  nextcloud:

The services in the Compose project share a network and reach each other by service name. The only way in is port 8081 on the server's own loopback address, where Caddy connects, so neither Nextcloud nor its database can be reached from the internet. The extra_hosts line lets Nextcloud reach its own public address, which it uses to check its setup.

4. Add the database and cache

MariaDB 11.8 is the version Nextcloud recommends, and READ-COMMITTED the setting it asks for. MARIADB_AUTO_UPGRADE updates the database files when a newer MariaDB image arrives.

5. Add Nextcloud

On its first start, the container installs Nextcloud with the user admin. Caddy's connections reach the Compose project from the server's own IPv4 address, so TRUSTED_PROXIES names that address: Nextcloud then takes each visitor's real IP address from what Caddy passes on, which it needs to slow down password guessing. The two OVERWRITE settings make Nextcloud's own links use HTTPS.

Version 34 is the one the image marks as stable. With the 34-apache tag, updates within 34 install themselves; you move to the next major version yourself (step 10).

Start it, and follow the log:

runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose up -d"
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose logs -f nextcloud-app"

The first start downloads about 2 GB of images and installs Nextcloud, which takes a few minutes. When the log says Nextcloud was successfully installed and then shows Apache starting, press Ctrl+C.

6. Put Caddy in front

Go back to root with exit, and switch to Caddy's user:

uid=$(id -u caddy)
runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  bash -lc "export DOCKER_HOST=unix:///run/user/$uid/docker.sock; cd /home/caddy/caddy && docker compose restart caddy"

Add this block to the end of /home/caddy/Caddyfile:

cloud.example.com {
    reverse_proxy 127.0.0.1:8081
    redir /.well-known/carddav /remote.php/dav/ 301
    redir /.well-known/caldav /remote.php/dav/ 301
    header Strict-Transport-Security "max-age=15552000; includeSubDomains"
}

And restart Caddy, which briefly interrupts every site it serves:

uid=$(id -u caddy)
runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  bash -lc "export DOCKER_HOST=unix:///run/user/$uid/docker.sock; cd /home/caddy/caddy && docker compose restart caddy"

Caddy gets a certificate for cloud.example.com and renews it by itself, and sends plain HTTP visitors on to HTTPS. The two redir lines let calendar and contacts apps find their way from just your server's name.

Go back to root with exit, and to Nextcloud's user with runuser. Show the admin password:

cat /home/nextcloud/nextcloud/admin.env

Open https://cloud.example.com and log in as admin.

7. Run background jobs

Nextcloud has regular tasks, such as cleaning up and sending notifications, which should run every five minutes. Make typing its occ command shorter first:

occ() {
  runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
    DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
    bash -lc "cd /home/nextcloud/nextcloud && docker compose exec -T -u www-data nextcloud-app php occ $*"
}
mkdir -p /home/nextcloud/.config/systemd/user

Create /home/nextcloud/.config/systemd/user/nextcloud-cron.service:

[Unit]
Description=Nextcloud background jobs

[Service]
Type=oneshot
WorkingDirectory=/home/nextcloud/nextcloud
ExecStart=/usr/bin/env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/%U \
  DOCKER_HOST=unix:///run/user/%U/docker.sock PATH=/usr/bin:/bin \
  /usr/bin/docker compose exec -T -u www-data nextcloud-app php -f /var/www/html/cron.php

And ~/.config/systemd/user/nextcloud-cron.timer:

[Unit]
Description=Run Nextcloud background jobs every 5 minutes

[Timer]
OnCalendar=*:0/5

[Install]
WantedBy=timers.target

Switch it on and tell Nextcloud to rely on it:

systemctl --user daemon-reload
systemctl --user enable --now nextcloud-cron.timer
occ background:cron

8. Finish the setup

occ config:system:set maintenance_window_start --type=integer --value=1
occ config:system:set default_phone_region --value=SE
occ maintenance:repair --include-expensive

The first line runs the heavy daily tasks in the four hours from 01:00 UTC, the second reads phone numbers without a country code as Swedish (use your own country's code), and the third finishes a task a new install leaves for you.

Under Administration settings → Overview, what remains are suggestions. Two are worth doing: set up email under Basic settings so Nextcloud can send password resets (your own mail server works), and turn on two-factor authentication for your users.

9. Keep it up to date

Add the weekly docker-update.service and docker-update.timer from the rootless Docker guide, with WorkingDirectory=/home/nextcloud/nextcloud, and enable the timer as nextcloud. That keeps all three services current.

That keeps all three containers current. When a newer Nextcloud 34 image arrives, the container upgrades Nextcloud when it restarts.

10. Move to a new major version

A new major version is a step you take yourself, one version at a time: Nextcloud cannot skip one. Back up first (step 11), then pause the background jobs so they do not run halfway through the upgrade, change the tag and restart:

systemctl --user stop nextcloud-cron.timer
sed -i 's|nextcloud:34-apache|nextcloud:35-apache|' /home/nextcloud/nextcloud/compose.yaml
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose up -d"

When the log shows Update successful, press Ctrl+C and start the background jobs again:

systemctl --user start nextcloud-cron.timer

11. Back up

umask 077
mkdir -p /home/nextcloud/backup
occ maintenance:mode --on
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/nextcloud/nextcloud && docker compose exec -T nextcloud-db sh -c "mariadb-dump --single-transaction -u nextcloud -p"\$MARIADB_PASSWORD" nextcloud"' > /home/nextcloud/backup/nextcloud-db.sql
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose exec -T nextcloud-app tar -C /var/www/html -czf - ." > /home/nextcloud/backup/nextcloud-files.tar
cp /home/nextcloud/nextcloud/db.env /home/nextcloud/backup/db-password
occ maintenance:mode --off

This saves the database, Nextcloud's files, settings and program in one archive, and the database password. Nextcloud is unavailable while it runs. umask 077 makes the files readable by nextcloud only. Copy /home/nextcloud/backup to another machine afterwards: a backup on the same server does not survive losing the server. Keep it private.

To restore into empty volumes, as nextcloud, with the backup in /home/nextcloud/backup:

systemctl --user stop nextcloud-cron.timer
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose down -v"
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose up -d"
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose exec -T nextcloud-app tar -C /var/www/html -xzf - < /home/nextcloud/backup/nextcloud-files.tar"
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/nextcloud/nextcloud && docker compose exec -T nextcloud-db sh -c "mariadb -u nextcloud -p"\$MARIADB_PASSWORD" nextcloud"' < /home/nextcloud/backup/nextcloud-db.sql
runuser -u nextcloud -- env HOME=/home/nextcloud XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc "cd /home/nextcloud/nextcloud && docker compose up -d"
occ maintenance:mode --off
systemctl --user start nextcloud-cron.timer

Starting the database also starts the other services, so stop Nextcloud before loading the backup, and the until line waits for MariaDB to be ready. The backup was taken in maintenance mode, so the restored Nextcloud starts in it too, and shows "maintenance mode" to everyone until the occ line switches it off. On a new server, create the database secret from the backup instead of a new one in step 2, since Nextcloud's settings in the archive name that password:

cp /home/nextcloud/backup/db-password /home/nextcloud/nextcloud/db.env
cp /home/nextcloud/backup/db-password /home/nextcloud/nextcloud/app-db.env

We restored on the same server, and the files, users and settings came back.

Connect your devices

  • Files: install the Nextcloud app on your computer or phone and enter https://cloud.example.com.
  • Calendars and contacts: add a CalDAV or CardDAV account (DAVx⁵ on Android, the built-in accounts on iPhone and Mac) with https://cloud.example.com and your user name. The app finds your calendars and address books by itself.

Troubleshooting

The log says missing table 'oc_federated_invites' and the Overview page suggests "Replica lag". Both are false alarms after an upgrade to Nextcloud 35. Nextcloud 35 removes that empty table on purpose, and the replica check does not apply to a single server. Neither needs action.

The browser says "Access through untrusted domain". The address you used is not the one in NEXTCLOUD_TRUSTED_DOMAINS, which only takes effect at install. To add one later: occ config:system:set trusted_domains 1 --value=cloud.example.com.

There is no certificate, or the browser warns about it. Check that the A and AAAA records point at the server, then read Caddy's log with journalctl --user -u caddy as the caddy user.

Every login appears to come from your server's own address. TRUSTED_PROXIES in step 5 must be the server's IPv4 address, the one Caddy's connections arrive from.

The Overview page says the Strict-Transport-Security header is not set, although Caddy sets it. Nextcloud could not reach itself through Caddy to check. The extra_hosts line in step 3 must name your Nextcloud's address.

Something is not running. As nextcloud, docker compose ps lists the containers shows the Compose project.

Your files, in Sweden

With Nextcloud on a Melonslab server, your files, calendars and contacts are stored in Sweden, under Swedish and EU law, on a server you control.

Run it on your own server

VC-S Micro

€7.99/mo

vCPU
2
Memory
8 GB
Storage
250 GB
Transfer
10 TB
Standard
HDD · RAID 10
  • Full root access
  • Native /64 IPv6
  • RAID-protected storage
  • Malmö, Sweden
  • Month to month, no lock-in
  • 7-day money-back guarantee

These steps were tested on VC-P Alloy. VC-S Micro has the same number of vCPUs and memory on an older CPU, and 250 GB of storage instead of 60 GB, which matters more here.

All guides