Mad World #Save_GAZA: Free Palestine  

Search

Nextcloud Docker Compose Setup for Production (2026): PostgreSQL, Redis, Cron, HTTPS with Caddy, Real Client IP, 2FA and a Tested Backup and Restore

Nextcloud Docker Compose Setup for Production (2026): PostgreSQL, Redis, Cron, HTTPS with Caddy, Real Client IP, 2FA and a Tested Backup and Restore

Nextcloud is a free, open-source file cloud that you run yourself: your files, synced to your laptop and phone, shared by link, with calendars and contacts, on your own server. This guide sets it up with Docker Compose the way you would run it for real use: PostgreSQL as the database, Redis for caching and file locks, a separate container for background jobs, and Caddy in front for HTTPS. Then it closes what a default install leaves open: the setup warnings, a gap in the client IP address that lets anyone dodge the brute-force protection, two-factor authentication for every account, and a backup that we restored to prove it works.

Tested on 25 and 26 November 2026 with Nextcloud 35.0.3 (image nextcloud:35.0.3-apache), PostgreSQL 18.7, Redis 8.8.4 and Caddy 2.11.9, on a home server with Ubuntu 26.04.1 LTS, Docker Engine 29.10.1 and Docker Compose v5.8.0 at 192.168.1.50, and a laptop on the same network at 192.168.1.21. Every command below ran there, and every screenshot shows its real output.

Quick answer: Nextcloud with Docker Compose, set up for production

In plain words: five containers work together. Nextcloud (the app) keeps your files in a folder on the server, and its accounts, shares and settings in a PostgreSQL database. Redis keeps short-lived data in memory, so pages are fast and two devices cannot change one file at the same moment. A cron container runs Nextcloud's background jobs every 5 minutes. Caddy is the front door: it speaks HTTPS and passes each request to Nextcloud. Only Caddy can be reached from your network.

  1. Create a folder with two random passwords, kept as Docker secrets.
  2. Write compose.yaml (pinned versions, a private network for the database and Redis) and a Caddyfile.
  3. Run docker compose up -d: Nextcloud installs itself with PostgreSQL in about a minute.
  4. Point the name cloud.home.arpa to the server and trust Caddy's certificate on your devices.
  5. Clear the setup warnings with a few occ commands.
  6. Set the e-mail server and send a test message.
  7. Keep APACHE_DISABLE_REWRITE_IP: "1" in the file, so nobody can choose the IP address Nextcloud sees.
  8. Give each sync app its own app password, then require two-factor authentication for everyone.
  9. Back up the database and the files, and test a restore before you need it.
Nextcloud Files list with after-2fa.txt uploaded a few seconds ago and notes.txt, both sent from a laptop over WebDAV with an app password
The result: files sent from a laptop over WebDAV with an app password. 1: uploaded after two-factor authentication was enforced. 2: the first upload, which also came back from the restore test.

What you need

  • A Linux server with Docker Engine and the Compose plugin: install Docker Compose on Ubuntu. Ports 80 and 443 must be free on it.
  • A name for the server. We used cloud.home.arpa, a name reserved for home networks, with Caddy's own certificate authority. Add it to your network's DNS (a Local DNS record in Pi-hole or a DNS rewrite in AdGuard Home) or to each device's hosts file.
  • An authenticator app on your phone for the two-factor step, and a mail account that can send through SMTP.
Terminal: Docker Engine 29.10.1, Docker Compose v5.8.0 and Ubuntu 26.04.1 LTS on the home server
The home server used for every step: Docker Engine 29.10.1, Docker Compose v5.8.0, Ubuntu 26.04.1 LTS.

The production setup at a glance

ContainerImageJobReachable from
caddycaddy:2.11.9-alpineHTTPS, HSTS, redirects, passes requests to the appYour network, ports 80 and 443
nextcloudnextcloud:35.0.3-apacheThe web app (Apache and PHP)Caddy only
nextcloud-cronnextcloud:35.0.3-apacheRuns cron.php every 5 minutesNo one (it only calls out)
nextcloud-dbpostgres:18.7-alpineThe databaseThe app, on a private network
nextcloud-redisredis:8.8.4-alpineFile locks and shared cacheThe app, on a private network

Step 1: create the folder and the secrets

Nextcloud needs two passwords: one for its PostgreSQL user and one for your admin account. Let the server make them, long and random, and keep them in files instead of writing them into compose.yaml. Docker Compose hands each file to the containers as a secret under /run/secrets/.

Terminal
mkdir -p ~/nextcloud && cd ~/nextcloud
install -d -m 700 secrets && (umask 022 && openssl rand -base64 36 | tr -d "\n" > secrets/postgres_password && openssl rand -base64 36 | tr -d "\n" > secrets/nextcloud_admin_password) && ls -ld secrets && ls -l secrets

The folder is 700: other users on the server cannot even list it. The files inside are 644 because the database container reads its password file as its own postgres user, not as you. Read your admin password once with cat secrets/nextcloud_admin_password and put it in your password manager.

Terminal: install -d -m 700 secrets and openssl rand create postgres_password and nextcloud_admin_password; ls shows drwx------ for the folder and two 48-byte files
Two random passwords of 48 characters. The folder is closed to other users (drwx------); the files are readable (rw-r--r--) so the database container can read its own.

Step 2: write compose.yaml and the Caddyfile

This is the complete file we ended with. Save it as ~/nextcloud/compose.yaml:

YAML
services:
  db:
    image: postgres:18.7-alpine
    container_name: nextcloud-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
    secrets:
      - postgres_password
    volumes:
      - ./db:/var/lib/postgresql
    networks:
      - backend
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U nextcloud -d nextcloud"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s
      start_interval: 5s

  redis:
    image: redis:8.8.4-alpine
    container_name: nextcloud-redis
    restart: unless-stopped
    networks:
      - backend
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 10s
      start_interval: 5s

  app:
    image: nextcloud:35.0.3-apache
    container_name: nextcloud
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      POSTGRES_HOST: db
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
      NEXTCLOUD_ADMIN_USER: igprod
      NEXTCLOUD_ADMIN_PASSWORD_FILE: /run/secrets/nextcloud_admin_password
      NEXTCLOUD_TRUSTED_DOMAINS: cloud.home.arpa
      REDIS_HOST: redis
      TRUSTED_PROXIES: 172.29.0.10
      OVERWRITEPROTOCOL: https
      OVERWRITECLIURL: https://cloud.home.arpa
      APACHE_DISABLE_REWRITE_IP: "1"
    secrets:
      - postgres_password
      - nextcloud_admin_password
    volumes:
      - ./html:/var/www/html
      - ./data:/var/www/html/data
    networks:
      - backend
      - frontend

  cron:
    image: nextcloud:35.0.3-apache
    container_name: nextcloud-cron
    restart: unless-stopped
    entrypoint: /cron.sh
    depends_on:
      - app
    volumes:
      - ./html:/var/www/html
      - ./data:/var/www/html/data
    networks:
      - backend
      - frontend

  caddy:
    image: caddy:2.11.9-alpine
    container_name: caddy
    restart: unless-stopped
    depends_on:
      - app
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy_data:/data
      - ./caddy_config:/config
    networks:
      frontend:
        ipv4_address: 172.29.0.10
        aliases:
          - cloud.home.arpa

networks:
  backend:
    internal: true
  frontend:
    ipam:
      config:
        - subnet: 172.29.0.0/24

secrets:
  postgres_password:
    file: ./secrets/postgres_password
  nextcloud_admin_password:
    file: ./secrets/nextcloud_admin_password

What each part does, and why it is set this way:

  • Pinned versions. nextcloud:35.0.3-apache instead of latest: an update happens when you change the tag, after a backup, never by surprise on a restart.
  • PostgreSQL 18 keeps its data in /var/lib/postgresql/18/docker, so the file mounts the parent folder, ./db:/var/lib/postgresql. On our server that gave db/18/docker. A future major version gets its own folder next to it.
  • Healthchecks with condition: service_healthy. Nextcloud starts only once PostgreSQL answers pg_isready and Redis answers PING, so the first install never races the database.
  • A private network. backend is internal: true: the database and Redis have no published port and no way out to the internet. Redis has no password, as in the image's own examples, because only the app and cron containers can reach it.
  • Caddy at a fixed address. 172.29.0.10 on the frontend network, and TRUSTED_PROXIES names exactly that address. The network alias cloud.home.arpa lets the containers reach Caddy under the server's name, which Nextcloud's own checks use.
  • OVERWRITEPROTOCOL and OVERWRITECLIURL make the links in e-mails and in occ output start with https://cloud.home.arpa.
  • APACHE_DISABLE_REWRITE_IP: "1" closes a gap in the client IP address. Step 7 shows the gap and the fix.
  • The cron container uses the same image with entrypoint: /cron.sh. Its schedule is */5 * * * * php -f /var/www/html/cron.php, the background job setup Nextcloud recommends.

Then the Caddyfile, next to it:

Code
cloud.home.arpa {
	# Caddy's own certificate authority: no public domain needed. With a public domain, delete this line.
	tls internal
	# Browsers keep to HTTPS for this name (Nextcloud's setup check asks for this header).
	header Strict-Transport-Security "max-age=15552000; includeSubDomains"
	# Calendar and contacts apps look for these two addresses.
	redir /.well-known/carddav /remote.php/dav/ 301
	redir /.well-known/caldav /remote.php/dav/ 301
	reverse_proxy app:80
}

tls internal makes Caddy its own certificate authority, so a home name works without a public domain. Check both files before the first start:

Terminal
docker compose config --quiet && echo "compose.yaml is valid"
Terminal: cat Caddyfile shows tls internal, the HSTS header, the two .well-known redirects and reverse_proxy app:80; docker compose config --quiet prints compose.yaml is valid
The Caddyfile, then Docker Compose reads compose.yaml without an error: "compose.yaml is valid".

Step 3: start Nextcloud

Terminal
docker compose up -d
docker compose ps --format "table {{.Name}}\t{{.Image}}\t{{.Status}}" && docker compose logs --no-log-prefix app | grep -E "^Initializing nextcloud|^New nextcloud|^Installing with|successfully installed|trusted_domains"

On the first start the app container copies Nextcloud into ./html, creates the database tables and your admin account from the secret, and adds cloud.home.arpa to the trusted domains. It took about a minute.

Terminal: docker compose up -d creates the networks and five containers, waits for db and redis to be healthy; ps shows all five up and the app log shows Nextcloud 35.0.3.2 installed with PostgreSQL
1: the two networks and five containers; Nextcloud waits until PostgreSQL and Redis report healthy. 2: about a minute later, the app's log says it installed itself with PostgreSQL and set the trusted domain.

Step 4: point the name to the server and check HTTPS

Each device must find cloud.home.arpa at the server's address. We added the line to the server's own hosts file and checked it:

Terminal
echo "192.168.1.50 cloud.home.arpa" | sudo tee -a /etc/hosts && getent hosts cloud.home.arpa

Caddy made its own root certificate on the first start. Copy it out; this file is what your devices must trust:

Terminal
docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt caddy-root.crt && openssl x509 -in caddy-root.crt -noout -subject -enddate
curl -sS --cacert caddy-root.crt https://cloud.home.arpa/status.php | jq . && curl -sSI http://cloud.home.arpa | head -n 3

Copy caddy-root.crt to each laptop and phone that uses Nextcloud and import it as a trusted root (the same steps as for an mkcert root). The laptop commands on this page also pass it to curl with --cacert, from the laptop's home folder. Only the public certificate leaves the server; Caddy's private key stays in ./caddy_data.

Terminal: the hosts line for cloud.home.arpa, Caddy root certificate copied to caddy-root.crt valid until 2036, status.php over HTTPS shows version 35.0.3.2 and HTTP answers 308 to HTTPS
1: the name points to the server. 2: Caddy's own root certificate, valid until 2036. 3: Nextcloud answers over HTTPS with that certificate checked, and plain HTTP is sent to HTTPS (308).

Step 5: clear the setup warnings with occ

Open https://cloud.home.arpa and log in as igprod (your admin user) with the password from Step 1. Then go to Administration settings > Overview, where Nextcloud runs its security and setup checks.

Nextcloud Administration overview, Security and setup warnings: three warnings (maintenance window, mimetype migrations, missing indices) and five recommendations
The checks on a fresh install. 1: three warnings. 2: five recommendations, from AppAPI to the server ID. Each one is fixed below.

Nextcloud's admin tool is occ. It must run inside the app container as the web server user, so a small helper saves typing:

Terminal
cat > occ <<"EOF"
#!/bin/sh
# Runs Nextcloud's occ command in the app container, as the web server user.
exec docker compose exec -u www-data app php occ "$@"
EOF
chmod +x occ && ./occ status
Terminal: a small occ script that runs docker compose exec -u www-data app php occ, then ./occ status shows installed true, version 35.0.3.2, maintenance false
1: a two-line helper, so every admin command is just ./occ. 2: the first command through it.

Then one command per item:

Code
./occ config:system:set maintenance_window_start --type=integer --value=1
./occ config:system:set default_phone_region --value=US
./occ config:system:set serverid --type=integer --value=1
./occ db:add-missing-indices
./occ maintenance:repair --include-expensive | tail -n 4
./occ app:disable app_api
./occ config:app:get core backgroundjobs_mode
  • Maintenance window: heavy daily jobs run from 01:00 UTC, when nobody uses the server.
  • Default phone region: use your own country code (US, GB, DE and so on).
  • Server ID: any number from 0 to 1023, different on each server if you ever run more than one.
  • Missing indices and mimetype migrations: db:add-missing-indices and maintenance:repair --include-expensive. Run them again after each major update.
  • AppAPI deploy daemon: AppAPI runs "External Apps" in Docker. If you do not use them, disable it.
  • Second factor and Email test: Steps 6 and 9.
Terminal: occ sets maintenance_window_start 1, default_phone_region US and serverid 1, adds the missing text_steps index, runs the expensive repair, disables app_api and shows backgroundjobs_mode cron
One command per warning. The last line shows that background jobs already run in Cron mode: the cron container set it on its first run.

Background jobs need nothing more: the cron container switched Nextcloud to Cron mode on its first run. Check it in Administration settings > Basic settings:

Nextcloud Basic settings, Background jobs: Last job ran 4 minutes ago and Cron (Recommended) selected, using the system cron service
Administration > Basic settings. 1: the last background job ran 4 minutes earlier. 2: Cron is selected; the cron container runs cron.php every 5 minutes.

Step 6: set up e-mail and send a test

Nextcloud sends password resets, share links and security notices by e-mail. First give your admin account an address; the test is sent there:

Code
./occ user:setting igprod settings email [email protected]

In a lab, Mailpit catches every message without sending anything out. We ran it on the home server with this file (skip it if you use your provider's SMTP server):

Terminal
mkdir -p ~/mailpit && cat > ~/mailpit/compose.yaml <<"EOF"
services:
  mailpit:
    image: axllent/mailpit:v1.34.0
    container_name: mailpit
    restart: unless-stopped
    ports:
      - "1025:1025"
      - "8025:8025"
EOF
cd ~/mailpit && docker compose up -d && docker compose ps --format "{{.Name}}: {{.Image}} {{.Status}}"
Terminal: a compose file for Mailpit v1.34.0 with ports 1025 and 8025, the container started, and occ setting admin@example.com as the admin account e-mail
Lab only: Mailpit catches every message on port 1025 and shows it on port 8025. Then the admin account gets an e-mail address, which the test needs.

Every other command on the home server runs in ~/nextcloud, so go back there with cd ~/nextcloud.

In Administration settings > Basic settings > Email server, set the sender and the server, click Save settings, then Send test email. With a real mail provider, use its server name and port 587 with None / STARTTLS, which switches to STARTTLS when the server offers it, turn on Authentication required with the account's user name and password, and leave Disable certificate verification off.

Nextcloud Basic settings, Email server: SMTP, From address nextcloud at cloud.home.arpa, server 192.168.1.50 port 1025, Save settings, Send test email and the message Email sent successfully
1: the sender address. 2: the mail server (here the lab's Mailpit). 3: Save settings (Nextcloud asks for your password first). 4: Send test email. 5: "Email sent successfully".
Mailpit inbox: one message from Nextcloud to admin@example.com, subject Email setting test, Well done, igprod
The test message arrived. 1: "Email setting test", sent to the admin account's address.

Step 7: stop clients from choosing their own IP address

Nextcloud slows down logins after failures, per client IP address: that is its brute-force protection. It only works if the address is the real one. The Apache image has a rule for that: it replaces the client address with the X-Real-IP header when the request comes from a private address. Caddy has a private address, and it passes that header on from the client unchanged. So any client can send its own X-Real-IP and pick the address Nextcloud blames.

We tested it from the laptop with a wrong password and a made-up address. Without APACHE_DISABLE_REWRITE_IP in the file:

Code
# on the laptop
curl --cacert caddy-root.crt -sS -o /dev/null -w '%{http_code}\n' -u igprod:not-the-password -H 'X-Real-IP: 203.0.113.9' https://cloud.home.arpa/remote.php/dav/files/igprod/
# on the server
./occ security:bruteforce:attempts 203.0.113.9
docker compose exec app cat /etc/apache2/conf-enabled/remoteip.conf
./occ security:bruteforce:attempts 192.168.1.21
Terminal: a login from the laptop with a made-up X-Real-IP header gets 401; the brute-force table counts the attempt for 203.0.113.9, the apache image trusts X-Real-IP from all private ranges, and the laptop address has 0 attempts
Without the fix. 1: a wrong password sent from the laptop with a made-up header, X-Real-IP: 203.0.113.9. 2: Nextcloud counted the failure for the made-up address. 3: why: the image trusts that header from any private address, Caddy's included. 4: the laptop's real address has no attempts.

The failure was counted for 203.0.113.9, an address that does not exist, and the laptop's real address stayed at 0. An attacker can change the header on every try and never be slowed down, or send a neighbour's address to get it blocked.

The fix is one line, already in the file of Step 2. With it, the entrypoint turns the header rule off, and Nextcloud reads the address from X-Forwarded-For, which it accepts only from TRUSTED_PROXIES, that is from Caddy. If you started without it, add it and recreate the app:

Code
sed -i '/OVERWRITECLIURL/a\      APACHE_DISABLE_REWRITE_IP: "1"' compose.yaml && grep -n -B2 'APACHE_DISABLE_REWRITE_IP' compose.yaml
docker compose up -d app
docker compose exec app sh -c 'ls /etc/apache2/conf-enabled | grep remoteip || echo "remoteip.conf: not enabled"'

The entrypoint tests only whether the variable exists (${APACHE_DISABLE_REWRITE_IP+x}), so any value turns the rule off, even "0". The same test afterwards:

Terminal: APACHE_DISABLE_REWRITE_IP 1 added to compose.yaml, the app recreated, remoteip.conf no longer enabled, the same spoofed login gets 401 and the attempt now counts for 192.168.1.21
1: the line added. 2: the app container recreated. 3: the header rule is gone. 4: the same request again. 5: the made-up address stays at 1, and the failure now counts for the laptop's real address.

The made-up address got nothing new, and the failure counted for 192.168.1.21, the laptop. We reset both counters afterwards with ./occ security:bruteforce:reset and the address.

Step 8: give each app its own app password

Sync apps, calendar apps and scripts should never use your account password. Give each one an app password: you can revoke it alone, and it keeps working once two-factor authentication is on. The Security page itself asks you to create one for each app before you switch on a second factor.

In Personal settings > Security > Devices & sessions, type a name such as laptop-backup and click Create new app password:

Nextcloud Security settings, New app password dialog for laptop-backup: login igprod, the generated password and its copy button
Personal settings > Security > Devices & sessions. 1: the login. 2: the app password, shown once. It belongs to a test server that no longer exists; treat yours like a password.

We used it from the laptop over WebDAV, the protocol behind the sync apps. curl reads it from ~/.netrc, a file only you can read, so the password never appears in a command line or in the shell history. The first command asks for it without showing what you type:

Code
(umask 077 && read -rs -p 'App password: ' P && printf 'machine cloud.home.arpa login igprod password %s\n' "$P" > ~/.netrc) && ls -l ~/.netrc
printf 'Nextcloud upload test from the laptop\n' > notes.txt && curl --netrc --cacert caddy-root.crt -sS -T notes.txt -o /dev/null -w '%{http_code}\n' https://cloud.home.arpa/remote.php/dav/files/igprod/notes.txt
curl --netrc --cacert caddy-root.crt -sS https://cloud.home.arpa/remote.php/dav/files/igprod/notes.txt
Terminal on the laptop: the app password goes into a 600 netrc file without being shown, curl uploads notes.txt with 201 Created and downloads it back
On the laptop. 1: the app password goes into ~/.netrc (rw-------) without showing on screen. 2: upload: 201 Created. 3: the file comes back.

The file is in Nextcloud, as the picture at the top of this page shows. Desktop and phone apps ask for the same login and app password, or use Show QR code for mobile apps in the same dialog.

Step 9: two-factor authentication for every account

Set it up for your own account first, so you cannot lock yourself out. In Personal settings > Security, tick Enable TOTP, scan the QR code with your authenticator app, type the code it shows and click Verify:

Nextcloud Security settings, TOTP (Authenticator app): the new TOTP secret, its QR code, a six-digit test code and the Verify button
1: the secret and its QR code for your authenticator app. 2: a code from the app, then Verify. It belongs to a test server that no longer exists; treat yours like a password.

Then click Generate backup codes in the same page:

Nextcloud Security settings, Backup code: ten one-time backup codes with Print backup codes and Save backup codes buttons
1: ten one-time codes for the day your phone is lost. 2: print them or save them somewhere safe, away from the server. These belong to a test server that no longer exists; treat yours like passwords.

Now require it for everyone. Users without a second factor are asked to set one up at their next login:

Code
./occ twofactorauth:state igprod
./occ twofactorauth:enforce --on
./occ twofactorauth:enforce
Terminal: occ twofactorauth:state shows totp and backup_codes enabled for igprod, then twofactorauth:enforce --on enforces two-factor authentication for all users
1: the admin account has both providers. 2: two-factor authentication is now required for every account. 3: the check.
Nextcloud login, TOTP (Authenticator app) page: authentication code field with a six-digit code, Submit, Use backup code and Cancel login
A new login now asks for the code after the password. 1: the six digits from the app, then Submit.

Last, the check that matters for your apps: with two-factor authentication on, the account password alone no longer opens WebDAV, and the app password still does.

Code
read -rs -p 'Nextcloud password: ' P && curl --cacert caddy-root.crt -sS -o /dev/null -w '%{http_code}\n' -u "igprod:$P" https://cloud.home.arpa/remote.php/dav/files/igprod/
printf 'Uploaded after 2FA was enforced\n' > after-2fa.txt && curl --netrc --cacert caddy-root.crt -sS -T after-2fa.txt -o /dev/null -w '%{http_code}\n' https://cloud.home.arpa/remote.php/dav/files/igprod/after-2fa.txt
Terminal on the laptop: WebDAV with the account password now gets 401, while an upload with the app password in netrc gets 201
With two-factor authentication on. 1: the account password alone no longer opens WebDAV: 401. 2: the app password still works: 201.

Step 10: back up Nextcloud

A backup is two things taken at the same moment: a dump of the database and a copy of the files. Maintenance mode stops all changes in between. We copied the whole folder except db, which the dump replaces: it holds the config, the data, the apps, the secrets and Caddy's certificate authority, so the same stack can start again from it.

Code
./occ maintenance:mode --on
mkdir -p ~/nextcloud-backups && (umask 077 && docker compose exec -T db pg_dump -U nextcloud -d nextcloud -Fc > ~/nextcloud-backups/nextcloud-db-$(date +%F).dump)
time (umask 077 && sudo tar -C ~/nextcloud --exclude=./db -czf - . > ~/nextcloud-backups/nextcloud-files-$(date +%F).tar.gz)
./occ maintenance:mode --off
ls -lh ~/nextcloud-backups

sudo is needed to read the data folder, which belongs to the web server user. umask 077 makes both files readable by you only: they hold your passwords and every user's files. Copy them off the server, to another disk and to a second place, and plan for the minute of maintenance mode at night.

Terminal: maintenance mode on, pg_dump to a 661K dump file, sudo tar of the folder without db in 57 seconds, maintenance mode off, both backup files mode 600
1: maintenance mode on. 2: the database dump. 3: the files, in 57 seconds. 4: maintenance off. 5: two files, readable by their owner only.

Step 11: test the restore

A backup you have never restored is a hope. We deleted a file, emptied the trash bin so only the backup could bring it back, then restored everything:

Code
# on the laptop
curl --netrc --cacert caddy-root.crt -sS -X DELETE -o /dev/null -w '%{http_code}\n' https://cloud.home.arpa/remote.php/dav/files/igprod/notes.txt && curl --netrc --cacert caddy-root.crt -sS -o /dev/null -w '%{http_code}\n' https://cloud.home.arpa/remote.php/dav/files/igprod/notes.txt
# on the server
./occ trashbin:cleanup --all-users
./occ maintenance:mode --on && docker compose stop app cron
Terminal: the laptop deletes notes.txt (204, then 404), occ empties the trash bins, maintenance mode on and the app and cron containers stopped
Breaking something to restore. 1: notes.txt deleted on the laptop (204), then gone (404). 2: the trash bin emptied too. 3: maintenance mode on; app and cron stopped.

Move the current folders aside instead of writing over them, so no file added after the backup stays behind. Then drop the database and load the dump. App and cron are stopped, so nothing holds a connection to it:

Terminal
sudo mv html html.before-restore && sudo mv data data.before-restore && sudo tar -C ~/nextcloud -xzf ~/nextcloud-backups/nextcloud-files-2026-11-26.tar.gz ./html ./data && sudo ls -ld html data
docker compose exec -T db dropdb -U nextcloud nextcloud && docker compose exec -T db createdb -U nextcloud -O nextcloud nextcloud && docker compose exec -T db pg_restore -U nextcloud -d nextcloud < ~/nextcloud-backups/nextcloud-db-2026-11-26.dump && echo "database restored"
Terminal: html and data moved aside and extracted from the backup archive, owned by www-data; the database dropped, created and restored with pg_restore
1: the current folders moved aside, the saved ones extracted. 2: the database dropped, created again and restored from the dump.

Empty Redis, which still holds the state from before, start the containers and leave maintenance mode. The copy was taken in maintenance mode, so the restored settings start in it too. maintenance:data-fingerprint tells the sync apps that the server went back in time, so they do not delete or overwrite files without asking:

Terminal
docker compose exec redis redis-cli FLUSHALL && docker compose start app cron && sleep 15 && ./occ maintenance:mode --off && ./occ maintenance:data-fingerprint
# on the laptop
curl --netrc --cacert caddy-root.crt -sS https://cloud.home.arpa/remote.php/dav/files/igprod/notes.txt
# on the server
sudo rm -rf html.before-restore data.before-restore && ./occ status
Terminal: redis flushed, app and cron started, maintenance mode off, data fingerprint updated; the laptop downloads notes.txt again; occ status shows maintenance false
1: Redis emptied, app and cron started, maintenance off, a new data fingerprint for the sync clients. 2: the deleted file is back. 3: the old folders removed; the status is normal.

Step 12: final checks

The overview again, after every step:

Nextcloud Security and setup warnings after the fixes: no errors and no warnings, one recommendation Errors in the log with 20 warnings since November 19, 2026
After every step. No errors, no warnings. 1: the one note left counts warnings written by the first background jobs after the install (see the log summary below).

To read those warnings yourself, summarize the log. Every one dates from the first background jobs on 25 November, among them the jobs of the AppAPI app disabled in Step 5. The check counts the last 7 days ("since November 19" on 26 November), so the note goes away once these entries are a week old:

Terminal
docker compose exec -u www-data app cat data/nextcloud.log | jq -r '"\(.time[0:10])  \(.message[0:58])"' | sort | uniq -c
Terminal: a jq summary of nextcloud.log: 16 Preview migration skipped, 1 updater backup clean-up skipped and 3 background jobs of the disabled AppAPI app, all on 2026-11-25
The 20 warnings: one-time notes from the first background jobs on 25 November, before the fixes. Nothing new since.

And what runs, and what it costs:

Terminal
docker compose ps --format "table {{.Name}}\t{{.Status}}\t{{.Ports}}"
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" nextcloud nextcloud-cron nextcloud-db nextcloud-redis caddy
Terminal: docker compose ps shows only caddy publishing ports 80 and 443; docker stats shows nextcloud 95.68MiB, db 60.37MiB, redis 18.55MiB and caddy 38.68MiB of memory
1: only Caddy publishes ports (80 and 443); the app, database and Redis have none. 2: memory at rest: about 214 MiB for the five containers.

Production checklist

SettingWhat it preventsChecked in
Passwords as Docker secrets in a 700 folderPasswords in compose.yaml, in shell history or readable by other usersStep 1
backend network with internal: trueDatabase and Redis reachable from the networkStep 12
Pinned image tagsSurprise major updates on a restartStep 2
HTTPS with HSTS, HTTP sent to HTTPS (308)Passwords and files sent in clearStep 4
APACHE_DISABLE_REWRITE_IP: "1" and TRUSTED_PROXIESClients choosing the IP address the brute-force protection seesStep 7
App passwords for every appYour account password stored in apps and scriptsStep 8
Two-factor authentication enforcedA stolen password being enough to log inStep 9
Backup in maintenance mode, files 600, restore testedLosing everything, or a backup that does not restoreSteps 10 and 11

Troubleshooting

"Last background job execution ran 56 years ago"

We saw this error right after the first start: no background job had run yet. It went away after the cron container's first run, five minutes later. If it stays, check that nextcloud-cron is up with docker compose ps.

A password box opens when you save a setting

That is Nextcloud's password confirmation: it asks for your account password again before it changes admin or security settings. We met it at Save settings in Step 6, at Create new app password in Step 8 and at Enable TOTP in Step 9. Type the password and the change goes through.

WebDAV or a sync app answers 401 with the right password

Two-factor authentication is on for that account, so the account password alone no longer works for apps (Step 9). Create an app password for the app.

Every login failure comes from the same address, or from a strange one

Check ./occ security:bruteforce:attempts with your own address after a wrong password. If the count lands on Caddy's address, TRUSTED_PROXIES does not match Caddy; if it lands on any address a client sends, the header rule of Step 7 is still on.

"Errors in the log" on a new server

Summarize the log as in Step 12. One-time notes from the first background jobs are normal; anything new after your changes is worth reading in full with ./occ log:tail.

What we did not test

A public domain with a Let's Encrypt certificate (we used tls internal), the Nextcloud desktop and phone apps (we used WebDAV with curl), Nextcloud Office, Talk, the All-in-One image, an upgrade to a new major version, object storage as primary storage, server-side encryption, Fail2ban or CrowdSec rules for Nextcloud, IPv6 and ARM boards. Everything else on this page ran on the machines described at the top.

Frequently asked questions

Is Nextcloud free?

Yes. Nextcloud Server is open source under the AGPL, and the Docker image is free. The company behind it sells support contracts for businesses.

Should I use the nextcloud image or Nextcloud All-in-One?

The nextcloud image used here is maintained by community volunteers and, in its own words, designed for expert use: you choose the database, the proxy and the backups, as on this page. Nextcloud All-in-One is maintained by Nextcloud GmbH and sets those parts up for you, with less control. We tested only the image.

Which database should Nextcloud use in Docker?

PostgreSQL, as here, or MariaDB/MySQL. Without database variables the image falls back to SQLite, which Nextcloud's system requirements list as "only recommended for testing and minimal-instances".

Does Nextcloud need Redis?

For more than one user, yes. With REDIS_HOST set, the image configures Redis for file locking and the shared cache, next to APCu for the local cache. On our server occ showed memcache.locking and memcache.distributed on Redis and memcache.local on APCu.

How much memory does Nextcloud use in Docker?

At rest, about 214 MiB for the five containers: 95.68 MiB for the app, 60.37 MiB for PostgreSQL, 38.68 MiB for Caddy, 18.55 MiB for Redis and under 1 MiB for cron. Large uploads, previews and many users take more.

How do I update Nextcloud in Docker?

Back up first (Step 10), change the image tag in compose.yaml and run docker compose up -d; the image runs the upgrade when it starts. Go one major version at a time: Nextcloud cannot skip major releases. Then run Step 5's index and repair commands again. We did not run an upgrade in this test.

How do I reach Nextcloud from outside my home?

The safest way is a VPN such as Tailscale: your devices reach the server as if they were at home, and no port is open to the internet. A public domain also works, but we did not test it here: put the domain in the Caddyfile and in compose.yaml in place of cloud.home.arpa, remove tls internal, and Caddy gets a public certificate once ports 80 and 443 reach it from the internet. Then keep Nextcloud updated and watch the brute-force counters.

Sources

Fatima Ezzahra

Fatima Ezzahra

Fatima Ezzahra covers AI tools, open-source projects and technology news for IGPROD.

Leave a comment

Your email address will not be published. Required fields are marked *

Your experience on this site will be improved by allowing cookies Cookie Policy