dankhostself-host anything

Nextcloud with Docker Compose

A safe home for all your data: store your files, contacts, calendars and more on a server of your choosing, keep them synchronised across your devices and share them with others. In the project's words: Nextcloud Server README checked 2026-09-23

Replaces: Microsoft 365. Nextcloud's own site calls it "the better Microsoft 365 for private clouds". nextcloud.com front page checked 2026-09-23

Runs on: amd64, arm64, ppc64le, s390x from each image's registry manifest, checked 2026-09-25; a CPU counts only if every image has a build for it. Image by image

Add Nextcloud to the builder to use your own domain, get its passwords generated in your browser, and combine it with other apps in one file.

What Nextcloud needs

Only figures Nextcloud's own documentation publishes, each linked to the page it is on. Where the project gives no number, this page does not invent one.

ResourceMinimumRecommended
RAM128 MB per PHP process512 MB per PHP process
Per PHP process, not per server: Nextcloud says the total varies greatly with the number of users, apps, files and server activity. The built-in updater needs at least 256 MB. Source: Nextcloud admin manual: System requirements (Memory) checked 2026-09-23
CPUThe project publishes no figure
No speed or core count. A 64-bit CPU, OS and PHP is "strongly recommended"; 32-bit works but cannot handle dates before 1970 or after 2038. Source: Nextcloud admin manual: System requirements (CPU Architecture and OS) checked 2026-09-23
DiskThe project publishes no figure

On top of this, Caddy (the reverse proxy in the file) is a single small container. Nextcloud itself runs as 3 containers: nextcloud-db, nextcloud-redis, nextcloud-app.

Which hardware Nextcloud has images for

Read from each image's manifest list in its registry (anonymous, read-only) when this page was built. An app counts for a CPU only if every one of its images lists it.

  • x86-64 PC or NAS (linux/amd64): every image has a build.
  • Raspberry Pi 4/5, 64-bit OS (linux/arm64): every image has a build.
  • Raspberry Pi 3 or Zero 2 W, 32-bit OS (linux/arm/v7): no image for db. No image for this hardware; the builder leaves the app out.
ServiceImagePlatforms in the manifestDigestRegistryChecked
dbmariadb:ltsamd64, arm64, ppc64le, s390xsha256:805c8e104bd563d5bfa24fadd3f31cd419ea859cb5277f32b5dbf2db714f9ed1registry-1.docker.io2026-09-25
redisredis:alpineamd64, arm/v6, arm/v7, arm64, 386, ppc64le, riscv64, s390xsha256:3811787313eba226a2ef38658c6ccb91cd5e110edc89c37767de373120a0e5a0registry-1.docker.io2026-09-25
appnextcloudamd64, arm/v5, arm/v7, arm64, 386, ppc64le, riscv64, s390xsha256:1969514cbcc9ae1e9a15ba2e388c7a0de5ee49ecd9c1da81e1e1a92d3dda46caregistry-1.docker.io2026-09-25

A manifest says an image exists for a CPU, not how well Nextcloud runs on it: a build for arm64 or arm/v7 can still be too slow or need more memory than the board has. The RAM and disk Nextcloud publishes are in the table above and, for a whole set of apps against a Raspberry Pi, on Will it run on my machine?. A tag like latest can move to a new digest after the date checked.

docker-compose.yml

This is exactly what the builder writes for Nextcloud alone on example.org: the official definition with its published ports removed and Caddy added in front. Every ${VARIABLE} is defined in the .env below.

# docker-compose.yml built at dankhost.com for: Nextcloud
# Each app block is its official compose definition. Only the names were prefixed with
# the app slug (services, containers, volumes, bind folders, .env variables) so any set of
# apps can share one file; other differences are listed under "Changed:" in each block.
# Only Caddy publishes ports. Secrets live in .env next to this file.

services:
  # ---- Caddy: the one reverse proxy, HTTPS certificates from Let's Encrypt ----
  # Source: https://caddyserver.com/docs/running (checked 2026-09-23)
  # Source: https://github.com/dani-garcia/vaultwarden/wiki/Using-Docker-Compose (checked 2026-09-23)
  # Caddyfile goes in ./caddy/Caddyfile. Fixed address 172.30.0.2 so apps can trust it exactly.
  caddy:
    image: "caddy:2"
    container_name: "caddy"
    restart: "unless-stopped"
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - "./caddy:/etc/caddy"
      - "caddy-data:/data"
      - "caddy-config:/config"
    networks:
      proxy:
        ipv4_address: "172.30.0.2"

  # ---- Nextcloud (cloud.example.org) ----
  # Source: https://github.com/nextcloud/docker (checked 2026-09-23)
  # Source: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html (checked 2026-09-23)
  # Changed: Removed the documented '8080:80' port; Caddy reaches the app on the proxy network.
  #          The documented blank MYSQL_ROOT_PASSWORD / MYSQL_PASSWORD are filled from generated secrets in .env.
  #          Added REDIS_HOST (the README's Redis caching variable) so the Redis container the example starts is actually used.
  #          Added NEXTCLOUD_ADMIN_USER/PASSWORD so the install finishes by itself and no stranger can claim the install wizard.
  #          Added the README's reverse-proxy variables: NEXTCLOUD_TRUSTED_DOMAINS, APACHE_DISABLE_REWRITE_IP, TRUSTED_PROXIES and OVERWRITEHOST/PROTOCOL/CLIURL.
  nextcloud-db:
    image: "mariadb:lts"
    container_name: "nextcloud-db"
    restart: "always"
    command: "--transaction-isolation=READ-COMMITTED"
    volumes:
      - "nextcloud-db:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: "${NEXTCLOUD_MYSQL_ROOT_PASSWORD}"
      MYSQL_PASSWORD: "${NEXTCLOUD_MYSQL_PASSWORD}"
      MYSQL_DATABASE: "nextcloud"
      MYSQL_USER: "nextcloud"
    networks:
      nextcloud-backend:
        aliases:
          - "db"
  nextcloud-redis:
    image: "redis:alpine"
    container_name: "nextcloud-redis"
    restart: "always"
    networks:
      nextcloud-backend:
        aliases:
          - "redis"
  nextcloud-app:
    image: "nextcloud"
    container_name: "nextcloud-app"
    restart: "always"
    depends_on:
      - "nextcloud-redis"
      - "nextcloud-db"
    volumes:
      - "nextcloud:/var/www/html"
    environment:
      MYSQL_PASSWORD: "${NEXTCLOUD_MYSQL_PASSWORD}"
      MYSQL_DATABASE: "nextcloud"
      MYSQL_USER: "nextcloud"
      MYSQL_HOST: "db"
      REDIS_HOST: "redis"
      NEXTCLOUD_ADMIN_USER: "admin"
      NEXTCLOUD_ADMIN_PASSWORD: "${NEXTCLOUD_ADMIN_PASSWORD}"
      NEXTCLOUD_TRUSTED_DOMAINS: "cloud.example.org"
      APACHE_DISABLE_REWRITE_IP: "1"
      TRUSTED_PROXIES: "172.30.0.2"
      OVERWRITEHOST: "cloud.example.org"
      OVERWRITEPROTOCOL: "https"
      OVERWRITECLIURL: "https://cloud.example.org"
    networks:
      proxy: {}
      nextcloud-backend:
        aliases:
          - "app"

networks:
  # Pinned so the trusted-proxy address given to each app (172.30.0.2) is exact.
  # If "docker compose up" reports "Pool overlaps", change 172.30.0 here, in Caddy's
  # ipv4_address and in every trusted-proxy value to a free 172.x.0 range.
  proxy:
    ipam:
      config:
        - subnet: "172.30.0.0/24"
          ip_range: "172.30.0.128/25"
          gateway: "172.30.0.1"
  nextcloud-backend:
    internal: true

volumes:
  caddy-data:
  caddy-config:
  nextcloud:
  nextcloud-db:

Caddyfile save as caddy/Caddyfile

Caddy gets and renews the HTTPS certificate for cloud.example.org by itself once the DNS record points at your server and ports 80 and 443 reach it.

# Caddyfile built at dankhost.com. Save it as ./caddy/Caddyfile next to docker-compose.yml.
# Caddy gets and renews a Let's Encrypt certificate for each name below by itself,
# once the DNS records point at this server and ports 80 and 443 reach it.

# Nextcloud
cloud.example.org {
	redir /.well-known/carddav /remote.php/dav/ 301
	redir /.well-known/caldav /remote.php/dav/ 301
	reverse_proxy nextcloud-app:80
}

Already running nginx, Nginx Proxy Manager, Caddy or Traefik? The reverse-proxy settings Nextcloud needs, for all four, each cited to Nextcloud's own docs.

.env

The secrets are left blank here on purpose: a password printed on a public page is the same for everyone who copies it. The builder fills them with random letters and digits made in your browser.

# .env for Nextcloud, from dankhost.com/app/nextcloud/. Fill the blank secrets before starting.
# Keep this file private (chmod 600).

# Nextcloud
# 32 random letters and digits: the builder fills this in your browser
NEXTCLOUD_MYSQL_ROOT_PASSWORD=
# 32 random letters and digits: the builder fills this in your browser
NEXTCLOUD_MYSQL_PASSWORD=
# 24 random letters and digits: the builder fills this in your browser
NEXTCLOUD_ADMIN_PASSWORD=

Changes from the official file

Besides prefixing every service, container, volume, folder and variable with nextcloud (so any set of apps can share one file), these are all the differences from what the project documents:

  • Removed the documented '8080:80' port; Caddy reaches the app on the proxy network.
  • The documented blank MYSQL_ROOT_PASSWORD / MYSQL_PASSWORD are filled from generated secrets in .env.
  • Added REDIS_HOST (the README's Redis caching variable) so the Redis container the example starts is actually used.
  • Added NEXTCLOUD_ADMIN_USER/PASSWORD so the install finishes by itself and no stranger can claim the install wizard.
  • Added the README's reverse-proxy variables: NEXTCLOUD_TRUSTED_DOMAINS, APACHE_DISABLE_REWRITE_IP, TRUSTED_PROXIES and OVERWRITEHOST/PROTOCOL/CLIURL.

Notes for Nextcloud behind the proxy

  • Log in as 'admin' with NEXTCLOUD_ADMIN_PASSWORD from .env. The first start takes a minute or two while the installer runs.
  • The two Caddy 'redir' lines are the ones Nextcloud's admin manual gives for CalDAV/CardDAV discovery; without them the security check warns and phone calendar apps cannot find the server.

How to run it

  1. At your DNS provider, add an A record named cloud on your domain pointing at the server's public IP address, and forward TCP 80, TCP 443 and UDP 443 to it.
  2. Save the three files in one folder: docker-compose.yml and .env side by side, the Caddyfile at ./caddy/Caddyfile. Replace example.org with your domain in the Caddyfile, the compose file and the .env, or let the builder do it.
  3. Fill the blank NEXTCLOUD_MYSQL_ROOT_PASSWORD, NEXTCLOUD_MYSQL_PASSWORD, NEXTCLOUD_ADMIN_PASSWORD in .env. The builder generates them; on the server, tr -dc A-Za-z0-9 </dev/urandom | head -c 32 prints 32 random letters and digits. Then chmod 600 .env.
  4. Start it:
    docker compose up -d
    docker compose logs -f caddy   # watch the certificate arrive
  5. Open the new address (cloud. plus your domain) in a browser and follow the notes above.

Back it up

Nextcloud's admin manual lists five things to keep: the config, data, theme and custom apps folders, and the database. In this compose all four folders are inside the nextcloud volume, and the database is dumped with mariadb-dump while Nextcloud is in maintenance mode.

Below is the BACKUP.md the builder writes next to the compose file above: which of its folders and volumes hold data, the dump command the project documents, rewritten for this file's service names, what to copy with which container stopped, and a restore check. Pick more apps in the builder and it covers them all in one file.

# BACKUP.md built at dankhost.com for: Nextcloud

What to copy from the docker-compose.yml built with this file, the database dump each project documents (rewritten for the service names in that file), what to copy with which container stopped, and how to check the result. Run every command in the folder that holds docker-compose.yml.

The folders are owned by the containers' users: put sudo in front of tar if it says "Permission denied". Named volumes live under /var/lib/docker/volumes, not next to the compose file, so they are copied through a throwaway ubuntu container (Docker's documented --volumes-from method). tar makes a full copy each run; for large folders an incremental tool (restic, borg, rsync) saves time and space.

Never run "docker compose down -v" on this file: it deletes the named volumes of every app in it.

## Before you start

    BACKUP=/mnt/backup/selfhost   # change this: a disk or machine other than this server's system disk
    mkdir -p "$BACKUP"

## Every time: the three stack files

    tar czf "$BACKUP/stack-files.tar.gz" docker-compose.yml .env caddy

.env holds the database passwords and secret keys the apps were set up with; keep this archive as private as the data.

## Caddy (the reverse proxy)

Caddy's docs: 'The data directory must not be treated as a cache.' It holds the TLS certificates and their private keys; without it Caddy has to ask Let's Encrypt for every certificate again.

- caddy-data (named volume, /data in caddy)
  BACK UP: TLS certificates, private keys, OCSP staples.
- caddy-config (named volume, /config in caddy)
  SKIP: the last active configuration, kept for 'caddy run --resume', which this setup does not use: it starts from the Caddyfile.
- ./caddy (/etc/caddy in caddy)
  IN stack-files.tar.gz: the Caddyfile, copied with the stack files above.

Copy (Caddy keeps serving while you copy):

    docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu tar cvf /backup/caddy-data.tar /data

Restore check:

    tar tf "$BACKUP/caddy-data.tar" > /dev/null && echo OK
    docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu bash -c "cd /data && tar xvf /backup/caddy-data.tar --strip 1"

Sources:
- Caddy docs: Conventions, Data directory: https://caddyserver.com/docs/conventions#data-directory (checked 2026-09-24)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-09-24)

## Nextcloud

Nextcloud's admin manual lists five things to keep: the config, data, theme and custom apps folders, and the database. In this compose all four folders are inside the nextcloud volume, and the database is dumped with mariadb-dump while Nextcloud is in maintenance mode.

What this compose mounts:
- nextcloud-db (named volume, /var/lib/mysql in nextcloud-db)
  COVERED BY THE COMMAND BELOW: MariaDB data files; copy them only with the database stopped.
- nextcloud (named volume, /var/www/html in nextcloud-app)
  BACK UP: Nextcloud's whole /var/www/html: config/ (config.php, with the instance's secrets), data/ (every user's files), custom_apps/ and themes/.

1. Nextcloud's backup page uses maintenance mode instead of stopping the server: it locks logged-in sessions and blocks new logins so files and database cannot drift apart.

    docker compose exec -u www-data nextcloud-app php occ maintenance:mode --on

2. Database dump for nextcloud-db:

    docker compose exec -T nextcloud-db sh -c 'mariadb-dump --single-transaction -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' > "$BACKUP/nextcloud-sqlbkp.bak"

   The manual's command is mariadb-dump --single-transaction -h [server] -u [username] -p[password] [db_name]. Here it runs inside the database container, which already has the user, password and database name in its environment, so no password is typed on the host. If you turned on 4-byte (emoji) support, the manual adds --default-character-set=utf8mb4.

3. Copy in maintenance mode:

    docker run --rm --volumes-from nextcloud-app -v "$BACKUP":/backup ubuntu tar cvf /backup/nextcloud.tar /var/www/html

4. Leave maintenance mode:

    docker compose exec -u www-data nextcloud-app php occ maintenance:mode --off

Restore check:

    grep -c 'Dump completed' "$BACKUP/nextcloud-sqlbkp.bak"   # 1 means mariadb-dump finished
    tar tf "$BACKUP/nextcloud.tar" > /dev/null && echo OK

Put a copy back (with Nextcloud stopped):

    docker run --rm --volumes-from nextcloud-app -v "$BACKUP":/backup ubuntu bash -c "cd /var/www/html && tar xvf /backup/nextcloud.tar --strip 3"

Nextcloud's restore page: put the folders back, drop and recreate the database, then load the dump. The last step with this file's names:

    docker compose exec -T nextcloud-db sh -c 'mariadb -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' < "$BACKUP/nextcloud-sqlbkp.bak"

Turn maintenance mode off afterwards. The restore page also covers re-syncing desktop clients after data recovery.

Sources:
- Nextcloud admin manual: Backup: https://docs.nextcloud.com/server/latest/admin_manual/maintenance/backup.html (checked 2026-09-24)
- Nextcloud admin manual: Restoring backup: https://docs.nextcloud.com/server/latest/admin_manual/maintenance/restore.html (checked 2026-09-24)
- nextcloud/docker README: Accessing the Nextcloud command-line interface (occ) with docker compose: https://github.com/nextcloud/docker#accessing-the-nextcloud-command-line-interface-occ (checked 2026-09-24)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-09-24)

Update it

What docker compose pull does depends only on how each image line in the compose file above is tagged. For Nextcloud as this page writes it:

ServiceImageHow it is pinnedWhat docker compose pull does
caddycaddy:2Major version only (tag 2)Takes the newest image tagged 2: minor and patch releases of 2, never 3. A new major version needs a tag edit.
nextcloud-db databasemariadb:ltsNot pinned: moving tag ltsMoves to the newest image published as lts, which can be a new major version.
nextcloud-redisredis:alpineNot pinned: moving tag alpineMoves to the newest image published as alpine, which can be a new major version.
nextcloud-appnextcloudNot pinned: no tag, which means latestMoves to the newest image published as latest, which can be a new major version.

Do not raise the major version of nextcloud-db by editing its tag. Its tag, lts, is not pinned, so docker compose pull can move it to a new major version by itself. Before the next pull, write the version it runs now into the tag (docker compose exec nextcloud-db mariadb --version prints it), then keep that tag when you update Nextcloud.

The MariaDB image's docs: on start it leaves an existing database untouched. Only when MARIADB_AUTO_UPGRADE is set does it run mariadb-upgrade to update the system tables for the new version, keeping a backup of them in the data folder, and MariaDB notes this can limit going back. Without it the system tables stay as they were; mariadb-upgrade is the tool that updates them. This file does not set MARIADB_AUTO_UPGRADE on nextcloud-db. Source: MariaDB Docker Official Image: MARIADB_AUTO_UPGRADE checked 2026-09-30

What Nextcloud's docs say about updating

The Nextcloud image's README: it is only possible to upgrade one major version at a time (14 to 15, then 15 to 16). With Compose you run docker compose pull and docker compose up -d; the container's start script sees that the image is newer than the data and runs the upgrade itself.

  • The image here is nextcloud with no tag, which means latest. If you leave it alone for a while, one pull can move it more than one major version, which the README says cannot work. To stay in control, write the major version you run in the tag (Administration settings > Overview shows it) and raise it by one at a time.
  • Nextcloud's admin manual: you cannot skip major releases; update to the latest point release of your current major version before moving to the next one, and after a major upgrade let the background migrations finish before the next one.
  • The admin manual also asks for a fresh backup before every upgrade.

Source: nextcloud/docker README: Update to a newer version checked 2026-09-30; Nextcloud admin manual: Upgrade (major releases, no skipping) checked 2026-09-30

The steps

  1. Back up first, as in Back it up above. An update can migrate Nextcloud's data on its first start and its database with it; the copy is the way back.
  2. Download the new images. Running containers are not touched yet:
    docker compose pull
  3. Recreate the containers whose image changed. Volumes and bind-mounted folders stay as they are:
    docker compose up -d
  4. Watch Nextcloud start (Ctrl+C stops following the log, not the app):
    docker compose logs -f nextcloud-app
  5. Optional: remove the old images the pull left without a tag. This covers every stack on the machine, not only this one:
    docker image prune

Docker's reference for these commands: Docker docs: docker compose pull checked 2026-09-30; Docker docs: docker compose up (recreates changed containers, keeps volumes) checked 2026-09-30; Docker docs: docker image prune checked 2026-09-30

Locked out? Reset the admin password

Sets a new password for one Nextcloud account; occ asks for it twice. Nextcloud's manual lists two easier ways first: the reset link on the login screen (only if your account has an email address and the server can send mail) and another admin resetting it for you.

Run Nextcloud's occ tool as the web server user in the app container. admin is the account this file creates (NEXTCLOUD_ADMIN_USER); put your own user name there if it differs. Source: Nextcloud admin manual: Resetting a lost admin password read 2026-10-03; nextcloud/docker README: Accessing the Nextcloud command-line interface (occ) read 2026-10-03

docker compose exec --user www-data nextcloud-app php occ user:resetpassword admin

Run the commands in the folder that holds docker-compose.yml. docker compose exec runs the command in the container that is already running: Docker docs: docker compose exec read 2026-10-03

Sources

Every page below was fetched on the date shown.

Add Nextcloud to the builder All one hundred apps

Made with AI tools. ยท Privacy