How to Install Nextcloud with Docker Compose (Step-by-Step)

Replace Dropbox and Google Drive with your own private cloud. A complete Nextcloud Docker Compose setup with PostgreSQL, Redis and automatic cron jobs.

Install Nextcloud with Docker Compose

A private file sync and share server with PostgreSQL and Redis, running on your home server.

Estimated time: PT1H

  1. Confirm Docker is installed

    You need Docker Engine and the Compose plugin on your server. Follow our Docker installation guide first if you haven't set it up yet.

  2. Create the project folders and .env file

    Create a nextcloud folder, then add a .env file holding your database and admin passwords, locked down with chmod 600.

  3. Write the docker-compose.yml

    Add four services: PostgreSQL for the database, Redis for caching, the Nextcloud app, and the cron container that runs background jobs.

  4. Start the stack and log in

    Run docker compose up -d, wait for the first-run installation to finish, then open http://your-server-ip:8080 and log in with the admin credentials from your .env file.

  5. Fix trusted domains and background jobs

    Add your server IP or hostname to the trusted domains list and switch background jobs from AJAX to Cron in the Nextcloud settings.

  6. Connect your devices and back it up

    Install the desktop and mobile clients, then set up a 3-2-1 backup for the database and data folder before you rely on it.

Dropbox’s free tier has been shrinking for years. Google Drive keeps changing what counts against your quota, and your “unlimited” plan quietly has limits again. Meanwhile, Nextcloud — the open-source file sync and share platform — does the same core job on hardware you already own: files sync between your devices, you can share links with anyone, and nobody else has a copy.

The catch is that Nextcloud is a real web application: a database, a caching layer, a web frontend and background jobs. Docker Compose is the honest way to run it as a beginner — one file describes the whole system, and one command starts it.

This guide sets up a clean, fast, family-ready Nextcloud using the official images with PostgreSQL and Redis. If you have never installed Docker, do that part first with our Docker installation guide — then come back here.

What you’ll end up with

  • Nextcloud at http://your-server-ip:8080 on your home network
  • Data stored in a folder you control on the server
  • Background jobs running properly via a dedicated cron container (this matters more than beginners expect)
  • A base you can later put behind Tailscale for remote access, without exposing ports to the internet

Step 1: Create the project and secrets

Terminal window
mkdir -p ~/nextcloud/data
cd ~/nextcloud
nano .env

Put your secrets in the .env file — never directly in the Compose file, so you can share or back up the Compose file without leaking passwords (use our password generator for strong random strings):

# Pick long, random passwords. Store them in your password manager.
DB_PASSWORD=change-me-to-something-long-random
ADMIN_PASSWORD=change-me-too

Lock down the file permissions so only your user can read it:

Terminal window
chmod 600 .env

Step 2: The docker-compose.yml

Terminal window
nano docker-compose.yml

Paste this:

services:
db:
image: postgres:17-alpine
container_name: nextcloud-db
restart: unless-stopped
volumes:
- nextcloud-db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=${DB_PASSWORD}
redis:
image: redis:7-alpine
container_name: nextcloud-redis
restart: unless-stopped
app:
image: nextcloud:apache
container_name: nextcloud-app
restart: unless-stopped
depends_on:
- db
- redis
ports:
- "8080:80"
volumes:
- ./data:/var/www/html
environment:
- POSTGRES_HOST=db
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=${DB_PASSWORD}
- REDIS_HOST=redis
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD}
- NEXTCLOUD_TRUSTED_DOMAINS=192.168.1.50
cron:
image: nextcloud:apache
container_name: nextcloud-cron
restart: unless-stopped
volumes:
- ./data:/var/www/html
entrypoint: /cron.sh
depends_on:
- db
- redis
volumes:
nextcloud-db:

Two things to change before saving:

  1. In NEXTCLOUD_TRUSTED_DOMAINS, replace 192.168.1.50 with your server’s actual LAN IP (run hostname -I to see it). There is a space-separated slot for more names — useful if you later give the server a local hostname like cloud.home.arpa.
  2. If port 8080 is already used by another container (like qBittorrent — check our default port lookup), change the left side of "8080:80" to any free host port such as "8088:80".

Note

Why PostgreSQL instead of the default SQLite? SQLite is fine for a quick test, but Nextcloud’s own documentation recommends a real database server for anything long-term — it prevents database-lock errors when desktop and mobile clients sync simultaneously, and keeps things fast once you pass thousands of files.

Step 3: Start it and log in

Terminal window
docker compose up -d

The app container performs the full installation on first boot (creating database tables, the admin account, and default config). Watch it finish:

Terminal window
docker compose logs -f app

Wait until the log settles down and Apache reports it is listening on port 80 (typically 45–90 seconds on an SSD). Press Ctrl+C to exit logs, then open in your browser:

http://YOUR-SERVER-IP:8080

Log in as admin with the ADMIN_PASSWORD from your .env file. You’ll land on the default Files dashboard with a sample folder structure ready to clean out or start syncing into.

Step 4: Trusted domains and background jobs

Two settings separate a hobbyist install from a solid one.

Trusted domains. If you ever access Nextcloud by another name (a local DNS hostname, or later through Tailscale), Nextcloud blocks the request with an “Access through untrusted domain” screen. Add extra names or IPs with occ:

Terminal window
docker exec -u www-data nextcloud-app php occ config:system:set trusted_domains 1 --value=cloud.home.arpa
docker exec -u www-data nextcloud-app php occ config:system:set trusted_domains 2 --value=100.x.y.z

Background jobs. By default Nextcloud processes previews, scans and cleanup in AJAX mode — meaning it only runs them while someone actively keeps a page open. The cron container you started fixes this properly:

  1. In Nextcloud, go to Settings → Administration → Basic settings.
  2. Under Background jobs, select Cron.

That’s it — the cron container now runs maintenance every 5 minutes, and the yellow/red warnings in the admin overview clear out on their own.

The occ command

occ is Nextcloud’s administrative command-line tool. Running it through the container with docker exec -u www-data nextcloud-app php occ … lets you add users, rescan files added manually on disk (files:scan –all), and apply database indices (db:add-missing-indices) after upgrades without clicking through menus.

Step 5: Connect your devices

  • Desktop: install the Nextcloud client for Windows, macOS or Linux from nextcloud.com/install and point it at http://YOUR-SERVER-IP:8080. It creates a local sync folder that behaves just like Dropbox. Over gigabit Ethernet, small-to-medium syncs saturate near 90–110 MB/s; over home Wi-Fi expect 25–60 MB/s.
  • Mobile: the Nextcloud app on iOS and Android handles document access plus calendar/contacts sync via CalDAV/CardDAV. If you mainly want fast photo browsing and AI search, pair Nextcloud for files with Immich for photos — splitting those two jobs is the cleanest setup on modest hardware.
  • Family: create separate accounts under Settings → Users and assign quotas so one phone backup doesn’t fill the entire disk.

Step 6: Updates that don’t break things

The update routine for this stack is short:

Terminal window
cd ~/nextcloud
# 1. Back up first — database dump + your data folder
docker exec nextcloud-db pg_dump -U nextcloud nextcloud > backup-$(date +%F).sql
# 2. Pull and recreate
docker compose pull
docker compose up -d

The app container runs the database schema upgrade automatically on start; in most cases you won’t notice more than a slightly slower first page load. The one rule: back up before every pull. Ninety-nine percent of updates are painless, and the hundredth is the one you’ll be glad you prepared for. Our 3-2-1 backup guide has the full automated routine.

Warning

The ./data folder holds not just your files but also Nextcloud’s config/config.php, installed apps and encryption salts. If you restore the PostgreSQL database without ./data — or vice versa — Nextcloud will refuse to boot cleanly. Back up both together, every time.

Troubleshooting the classics

  • “Access through untrusted domain” — working as designed: add the IP or hostname you typed into trusted_domains per step 4.
  • “Your data directory is invalid” or permission errors — make sure ./data and its subfolders are readable/writable by UID 33 (www-data inside nextcloud:apache). Run sudo chown -R 33:33 ~/nextcloud/data if you edited files on the host as root, and run docker exec -u www-data nextcloud-app php occ maintenance:repair.
  • Slow after installing — check that Background jobs shows Cron in Administration → Overview, and confirm Redis is active (without Redis, every web request hits PostgreSQL for file locks).
  • Big file uploads failing behind a reverse proxy — if you later put Nginx Proxy Manager in front of Nextcloud, increase client_max_body_size (e.g. 10G) in the proxy’s custom config; on direct LAN port 8080, Nextcloud chunks large uploads automatically.

Where to go from here

  • Remote access the safe way: Tailscale instead of opening ports
  • Split responsibilities: Nextcloud for files and docs, Immich for photos, Jellyfin for media
  • Look after it: 3-2-1 backups and regular updates

Used daily for documents, spreadsheets and desktop folder sync across Linux and Windows, Nextcloud feels virtually identical to Dropbox once Redis and Cron are wired up — the only part you should deliberately hand off elsewhere is massive photo galleries, where Immich is noticeably snappier.

Frequently Asked Questions

Is this the official Nextcloud installation method?

There are two official paths: Nextcloud All-in-One (AIO), which bundles everything via a management container, and the manual Docker Compose setup shown here using the official nextcloud:apache image with PostgreSQL and Redis. Manual Compose gives you transparent control over ports, volumes and updates alongside your other stacks, which is why most self-hosters prefer it.

How much RAM does Nextcloud need?

2 GB is workable for a family setup, 4 GB is comfortable when running alongside other services. The web app itself is modest — the database and Redis are there to keep it responsive as your file count grows.

Can I access Nextcloud from outside my home?

Yes, but do it safely. The recommended beginner path is Tailscale, which puts your phone and laptop on the same private network as the server without opening any ports. We cover that in the networking section. If you must expose it publicly, put it behind a reverse proxy with HTTPS and keep it updated — never port-forward raw HTTP.

How do I update Nextcloud without breaking it?

Pull the new image, bring the stack back up, and let the automatic upgrade run — but back up the database and data folder first, every time. Our backup guide covers the exact routine. Do not skip major-version upgrades for many versions; update regularly instead.

Is Nextcloud fast enough to replace Google Drive for a family?

For sync, file sharing and mobile auto-upload, yes — it is easily fast enough on modest hardware. Where you will notice the difference is photos browsing on huge libraries, which is one reason many people pair Nextcloud for files with Immich for photos. See our Immich vs Google Photos comparison.

Portrait of Guillermo

Written by Guillermo

IT Student & Home Server Enthusiast

Building private clouds to break free from Big Tech. I document everything I learn about home servers and self-hosting on MyHomeServerGuide.

More about the author