I rebuilt my Nextcloud stack from an empty directory on 2 December. docker compose up -d at 04:34 UTC, the app container running two minutes nineteen seconds later, and occ status reporting installed: true before 04:37. No wizard to click through, no database to create by hand. The compose file does all of it.
Then I opened the admin Overview page and found a red box: "Last background job execution ran 56 years ago. Something seems wrong."
That's the shape of every Nextcloud Docker install I've done. The webserver comes up so cleanly that you assume the work is finished. It isn't. Nextcloud 35 ships 68 setup checks, and my install still opened with five of them non-green, including the one that quietly decides whether files get indexed, shares expire and trash gets emptied. Here is the compose file I used, what it reported, and the changes that took the page from five non-green checks to none.
Nextcloud Docker install: the compose file I used
Three services. Nextcloud, MariaDB 11.4 and Redis, with named volumes so nothing lives inside a container that can be replaced.
services:
db:
image: mariadb:11.4
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: unless-stopped
volumes:
- db:/var/lib/mysql environment:
- MYSQL_ROOT_PASSWORD=changeme
- MYSQL_PASSWORD=changeme
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
redis:
image: redis:7-alpine
restart: unless-stopped
app:
image: nextcloud:apache
restart: unless-stopped
ports:
- 8080:80 volumes:
- nc:/var/www/html environment:
- MYSQL_HOST=db
- MYSQL_PASSWORD=changeme
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- REDIS_HOST=redis
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=changeme
- NEXTCLOUD_TRUSTED_DOMAINS=files.example.com localhost
- PHP_MEMORY_LIMIT=512M
- PHP_UPLOAD_LIMIT=10G depends_on:
- db
- redis
volumes:
db:
nc:
Environment variables are the part people skip. With NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD set, the entrypoint runs the installer by itself. With REDIS_HOST set, the image writes two keys into config.php that you can't add from the admin UI:
'memcache.local' => '\\OC\\Memcache\\APCu',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
Without that line there's no distributed cache and no lock backend, so file locking falls back to doing its work in the database. That is the setting behind the "no memory cache configured" warning on the Overview page.
Images pulled: 2.13 GB for nextcloud:apache, 456 MB for MariaDB, 58.5 MB for Redis. The finished install put 6.4 MB of tables in the database.
Two things in the generated config.php are worth knowing early. The image sets 'upgrade.disable-web' => true, so the upgrade button in the admin settings doesn't appear and upgrades happen by changing the image tag. And my trusted_domains array came back as localhost, localhost, 127.0.0.1, because the entrypoint adds localhost whether you list it or not. Neither is a problem. Both are reasons to stop editing that file by hand and use occ config:system:set.
What the fresh install reported
I ran occ setupchecks --output=json and counted by severity. 55 passed, 8 were informational, 4 were warnings, 1 was an error.
| Check | Severity | What it said |
|---|---|---|
| Background job last run | error | ran 56 years ago, which is the epoch sentinel and means never |
| Maintenance window | warning | no start time set, so heavy jobs run whenever they like |
| Mimetype migrations | warning | pending, run occ maintenance:repair --include-expensive
|
| Database configuration | warning | 3 advisor findings against the MariaDB defaults |
| HTTP headers | warning | no Strict-Transport-Security header |
None of this stopped logins. All of it mattered within a day.
Fix the background jobs first
A container ships with background jobs set to AJAX mode. That means jobs only run when somebody loads a page, and on a small instance nobody loads pages. File scanning stalls, share expiry never fires, and the trash keeps growing. One command changes the mode:
docker compose exec -u www-data app php occ background:cron
Changing the mode is half the job. Something still has to execute the queue, and the image has /cron.sh at the root for exactly this. Add a fourth service that reuses the same image and runs it:
` cron:
image: nextcloud:apache
restart: unless-stopped
volumes:
- nc:/var/www/html entrypoint: /cron.sh`
My first manual run took 2 minutes 37 seconds. Almost all of it was one job, UpdateAvailableNotifications at 129,915 ms, because it was the first time it had ever run and it had months of app releases to look up. Later runs are seconds. If you set the cron interval to a minute and see runs finishing in 40ms, that's normal. It's only running the jobs that are due. The whole queue doesn't run again.
Set the maintenance window while you're in there. Mine runs at 01:00 UTC, which is 06:30 in India and the quietest hour this box has:
docker compose exec -u www-data app php occ config:system:set maintenance_window_start --type=integer --value=1
docker compose exec -u www-data app php occ maintenance:repair --include-expensive
The repair run took 2.3 seconds on this empty instance and cleared the mimetype warning. On a real instance with a million files, budget an hour.
The domain and proxy settings you need before the first login
If your users reach the box through a hostname that is not in trusted_domains, Nextcloud answers with HTTP 400 and a page that says "Access through untrusted domain". I hit it by sending a request with a Host header of files.example.com while the environment variable listed only localhost. The page gives no hint of which value it wanted, so the fix means knowing the setting exists.
Behind nginx or Caddy, three more settings matter. Without trusted_proxies Nextcloud sees every request coming from the proxy's address, so the brute force throttler counts all your users as one client and the security check reports that your remote address could not be determined.
docker compose exec -u www-data app php occ config:system:set trusted_proxies 0 --value 172.18.0.1
docker compose exec -u www-data app php occ config:system:set overwriteprotocol --value https
docker compose exec -u www-data app php occ config:system:set overwrite.cli.url --value https://files.example.com
docker compose exec -u www-data app php occ config:system:set default_phone_region --value=IN
Use the proxy's address on the Docker network, or the whole subnet if the proxy container can change IP. Get these wrong and you get two things at once: links in share emails pointing at http://, and share links pointing at an internal hostname that means nothing to the person clicking it. The phone region line is separate and small. Without it, phone numbers in profiles are accepted unvalidated, and Nextcloud nags about it forever.
MariaDB defaults that fail Nextcloud's own audit
The database warning was the interesting one, because occ db:info said everything was fine while the Overview page still counted three advisor findings. Those two commands check different things. db:info prints six rows and grades them. The advisor behind the Overview page carries dozens of rules ported from phpMyAdmin, and three of them fire on a stock mariadb:11.4 container.
I found them by reading the rule set on disk and matching it against the server variables. The one that becomes a warning is InnoDB's redo log. MariaDB 11.4 ships innodb_log_file_size at 96 MiB (100,663,296 bytes) and the rule wants at least 128 MiB. Two more are notices: the slow query log is off, and long_query_time is 10 seconds, so a query can crawl for nine seconds without being recorded.
One line in the compose file fixes all three, plus the buffer pool, which defaults to 128 MB:
command: >-
--transaction-isolation=READ-COMMITTED
--binlog-format=ROW
--innodb-buffer-pool-size=1G
--innodb-log-file-size=256M
--slow-query-log=1
--long-query-time=2
--tmp-table-size=64M
--max-heap-table-size=64M
Keep tmp_table_size and max_heap_table_size equal. When they differ, MySQL silently caps the smaller one, and you spend an evening wondering why your 64 MB setting never shows up. Recreate the db container, and the database warning disappears. That gave me a page with 61 green checks, 7 informational, one warning left.
HSTS, and why the file has to be mounted
The last check wants an HSTS header. You can add it in Apache inside the container, watch it go green, then lose it the next time the container is recreated. I mounted the file instead:
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
Saved as ./hsts.conf and mounted at /etc/apache2/conf-enabled/hsts.conf:ro, a graceful Apache reload picked it up and curl -I showed the header on the login page. If you serve Nextcloud through nginx, put it there instead, once, and leave the app container alone.
Page time after all this: 147ms to 544ms for the login page over localhost, first request warm. Not a benchmark, just proof the thing answers.
What I didn't fix
I tore the stack down after measuring, so none of these numbers come from a used instance. I didn't test a bind mount, which is where ownership bites people: the container runs as uid 33, and a root-owned host directory gives you the "your data directory must be writable" error page. I didn't add SMTP either, so the email check stays informational. Object storage, external S3 and group folders were out of scope for the day. And I ran no load test at all: one admin user, 83 files in the file cache.
That last number is why I'm not going to tell you this compose file is production ready for fifty users. It's a correct starting point that passes Nextcloud's own audit. Capacity is a different afternoon.
How this was tested: a fresh three-service stack on an 8 vCPU VPS, Nextcloud 35.0.3, PHP 8.5.13, MariaDB 11.4.14, Redis 7, torn down after the checks were captured. I wrote it from the terminal output, with AI help on the editing pass.
If you'd rather not spend that afternoon, I set up and tune Nextcloud for small teams, including the reverse proxy and the backup side of it. What I do is here, and if you are still deciding between paying for storage and running your own, the cost comparison is here.
Nextcloud Docker questions I keep answering
How long does a Nextcloud Docker install take?
Two minutes nineteen seconds from docker compose up -d to a running app container, then under a minute for the installer. The first run is slower because nextcloud:apache is 2.13 GB to pull. The setup checks afterwards are where the hour goes.
Why does Nextcloud say access through untrusted domain?
The hostname in your browser is not in trusted_domains. Add it with occ config:system:set trusted_domains 1 --value=files.example.com, or list it in NEXTCLOUD_TRUSTED_DOMAINS before the first start. The error page never says which hostname it rejected.
Do I need Redis for Nextcloud in Docker?
Logins work without it. With REDIS_HOST unset, the image writes no distributed cache and no lock backend, so file locking runs in MariaDB. Two users won't notice. Twenty will.
How do I upgrade a Nextcloud Docker install?
Change the image tag and recreate the container, because the image sets 'upgrade.disable-web' => true and hides the web updater. Back up the database and the data volume first, then let the entrypoint run the migration.
Originally published on SelfHost Pilot - practical self-hosted software and private AI, tested on a real server.
This article was written with the help of AI (our own publishing automation) and reviewed by a human before posting.
Top comments (1)
SelfHost Pilot, the number that reframes this for me is not the 1 error — it is 55 passed on a system that had never run a background job. The only error, "last background job execution ran 56 years ago," is the epoch sentinel for never, and it still leaves 55 checks green, so the audit reads as mostly healthy on a stack that has done no work yet. Your first manual cron run makes the same point from the other side: 2 minutes 37 seconds, almost all of it one job, UpdateAvailableNotifications at 129,915 ms, because it had months of releases to catch up on — a one-off, not a steady state. But you tore the stack down after measuring, so the number I actually want is missing: what did the second cron run take, and did a re-run of occ setupchecks come back with zero warnings after the cron service, the 01:00 UTC maintenance window, and the MariaDB changes? That re-run is the proof the 5 red checks are fixed rather than just patched in the compose file. Did you capture it before tearing the stack down, or is that the next run to do?