Install Nextcloud with Docker Compose: The Full Setup, Tested
Nextcloud's own compose file gets you a working server with one command and the setup page, but it never connects the Redis it starts and nothing runs background jobs. Add REDIS_HOST, a cron service and a version number, all from Nextcloud's own examples.
The compose file in Nextcloud's official Docker README gets you a working Nextcloud:
fill in its two empty passwords, run docker compose up -d, and finish the
setup page in your browser. But that file leaves two jobs undone. It starts a Redis
container and never tells Nextcloud about it, and nothing in it runs Nextcloud's
background jobs. Both fixes come from the examples folder of the same GitHub project:
one line, REDIS_HOST=redis, on the app, and a fourth service called
cron. While you are in the file, put a version on the image.
We tested this in November 2026 with the README's "Base version - apache" file
(nextcloud, which was Nextcloud 35.0.2, plus mariadb:lts and
redis:alpine), run with Docker Compose v2 on a Linux server. The only
changes to the README's file were the two passwords and the host port (8116, because
8080 was taken on our server).
Which Nextcloud Docker setup is this?
The community-maintained nextcloud image, from
github.com/nextcloud/docker. Its
README opens with a warning: the image is "maintained by community volunteers and
designed for expert use", and for quick and easy it points to Nextcloud
All-in-One, a single container that manages the rest for you. This guide is the
compose route the same README documents, where you see and control every piece.
What does the compose file set up?
Three containers and two volumes. db is MariaDB, with its data in the
db volume. redis is Redis. app is Nextcloud,
with the program, your settings and your files in the nextcloud volume,
and the same database name, user and password as the database, with
MYSQL_HOST=db. The containers can be deleted and recreated; as long as the
volumes stay, nothing is lost. The README leaves MYSQL_ROOT_PASSWORD and
MYSQL_PASSWORD empty and says to fill them in before you start.
How do I install it, step by step?
- Save the file below as
compose.yamlin a folder of its own, with your own passwords in place of thechange-mevalues. - In that folder, run
docker compose up -d. The first time, Docker downloads the images first. - Open
http://<your server's address>:8080/in a browser: the address your other devices will use, notlocalhost. - Nextcloud's setup page says Autoconfig file detected. Under
Storage & database the database is already filled in from the
compose file (MySQL/MariaDB, user
nextcloud, databasenextcloud, hostdb). Create the admin account and click Install. - On Recommended apps you can click Skip; every one can be added later from Apps.
What does the README's file leave out?
After the install, Administration settings → Overview shows "Transactional File
Locking: The database is used for transactional file locking." Redis is running,
but the app section has no REDIS_HOST, so Nextcloud never uses it. And
Basic settings → Background jobs is on AJAX, which runs one job each
time someone loads a page. Cron is the recommended setting, and nothing in the file
runs it.
The fixed file, with the three changes marked. The cron service and the
REDIS_HOST line follow the project's own
.examples/docker-compose/insecure/mariadb/apache/compose.yaml:
services:
db:
image: mariadb:lts
restart: always
command: --transaction-isolation=READ-COMMITTED
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=change-me-root
- MYSQL_PASSWORD=change-me-db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
redis:
image: redis:alpine
restart: always
app:
image: nextcloud:35-apache # changed: a version, not latest
restart: always
ports:
- 8080:80
depends_on:
- redis
- db
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=change-me-db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- REDIS_HOST=redis # added: Nextcloud uses the Redis above
cron: # added: runs background jobs every 5 minutes
image: nextcloud:35-apache
restart: always
volumes:
- nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- db
- redis
volumes:
nextcloud:
db:
Run docker compose up -d again. Docker recreates the app with the new
setting and starts the cron container; the volumes, and so the install and its files,
stay. When the cron container first runs, Nextcloud switches Background jobs to
Cron by itself (in our test that took a few minutes, because
cron.sh runs every five), and the file locking note disappears from the
Overview.
Why put a version on the image?
Plain image: nextcloud means the latest release. Nextcloud cannot skip
a major version when it updates, so a server left on latest can be pulled
too far ahead and refuse to start. Pin the major version on both app and
cron, and move up one version at a time:
how to update Nextcloud in Docker.
Why does it say "Access through untrusted domain"?
A setup-page install trusts the address you installed from, and Nextcloud always
allows localhost. Open the same server by any other name or address (a
second network address, or a domain you add later) and you get Access through
untrusted domain. Add an address with:
docker compose exec -u www-data app php occ config:system:set trusted_domains 1 --value=cloud.example.com
Adding NEXTCLOUD_TRUSTED_DOMAINS to the compose file now will not do
it: the image applies that variable only during an install it runs itself, with
NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD set. More
in the untrusted domain fix.
What's left before it goes on the internet?
HTTPS. The README's file has no encryption and says so: it is meant to sit behind a
reverse proxy, and the README calls encryption mandatory once the server is reachable
from the internet. Two of the remaining Overview warnings (HTTP access, and the
Strict-Transport-Security header) are about exactly that, and are
handled at the proxy. For the desktop and
phone apps, give them the same address you installed from.
More guides for your own server: self-hosting with Nextcloud.
Full video transcript
1
00:00:00,000 --> 00:00:04,938
Nextcloud's own compose file gets you
a working Nextcloud with one command.
2
00:00:04,978 --> 00:00:09,518
But it leaves two jobs undone. It
starts Redis and never connects it.
3
00:00:09,558 --> 00:00:11,974
And nothing runs the background jobs.
4
00:00:12,014 --> 00:00:17,190
I'll install it start to finish, then
fix both, from Nextcloud's own examples.
5
00:00:17,590 --> 00:00:21,121
This is the official Nextcloud
Docker image, on GitHub.
6
00:00:21,161 --> 00:00:25,707
I'm installing it on a Linux server
I run myself, following this page.
7
00:00:26,919 --> 00:00:28,908
Read the warning at the top first.
8
00:00:28,948 --> 00:00:33,564
This image is maintained by community
volunteers, and designed for expert use.
9
00:00:33,604 --> 00:00:37,902
For quick and easy, the page points
you to Nextcloud All-in-One instead.
10
00:00:39,161 --> 00:00:43,602
All-in-One is a single container that
sets up and manages the rest for you.
11
00:00:43,642 --> 00:00:47,725
This video takes the other route,
the compose file on this same page.
12
00:00:47,765 --> 00:00:50,753
You see every piece, and
you can change any of it.
13
00:00:52,012 --> 00:00:55,631
Here's that compose file. It
describes three containers.
14
00:00:55,671 --> 00:01:00,400
The first is the database, MariaDB.
Its data lives in a volume called db.
15
00:01:00,440 --> 00:01:03,928
Now look at these two lines.
Both passwords are empty.
16
00:01:03,968 --> 00:01:06,999
The page says to fill
them in before you start.
17
00:01:07,039 --> 00:01:10,763
So pick two long passwords,
and keep them somewhere safe.
18
00:01:12,042 --> 00:01:13,706
The second container is Redis.
19
00:01:13,746 --> 00:01:17,512
It's a small memory store that can
take some work off the database.
20
00:01:17,552 --> 00:01:20,223
Remember that it's here.
We'll come back to it.
21
00:01:21,463 --> 00:01:25,442
The third is Nextcloud itself. The
image is just called nextcloud.
22
00:01:25,482 --> 00:01:29,948
The port line sends port eight zero
eight zero on the server to Nextcloud.
23
00:01:29,988 --> 00:01:34,698
Its volume, called nextcloud, holds the
program, your settings and your files.
24
00:01:34,738 --> 00:01:37,560
Then the same database
name, user and password.
25
00:01:37,600 --> 00:01:42,168
And the database host, which is simply
db, the name of the first container.
26
00:01:43,466 --> 00:01:46,552
So the picture is three
containers, and two volumes.
27
00:01:46,592 --> 00:01:51,422
The containers are the programs. The
volumes are where everything you keep lives.
28
00:01:51,462 --> 00:01:53,105
That's the part to remember.
29
00:01:53,145 --> 00:01:57,855
You can delete a container and make a
new one, and as long as the volumes stay,
30
00:01:57,895 --> 00:01:58,857
nothing is lost.
31
00:02:00,128 --> 00:02:03,719
Save the file as compose dot
yaml, in a folder of its own.
32
00:02:03,759 --> 00:02:06,975
Then, in that folder, run
docker compose up, dash d.
33
00:02:07,015 --> 00:02:11,420
Dash d keeps it running in the
background after you close the terminal.
34
00:02:11,460 --> 00:02:16,030
The first time, Docker downloads the
three images before anything starts.
35
00:02:17,304 --> 00:02:18,848
Now open it in a browser,
36
00:02:18,888 --> 00:02:22,587
at the server's network address
and the port from the file.
37
00:02:22,627 --> 00:02:27,847
On this server I changed the port, because
eight zero eight zero was already taken.
38
00:02:27,887 --> 00:02:32,600
That and the passwords are my only
changes. This is Nextcloud's setup page.
39
00:02:32,640 --> 00:02:36,949
Autoconfig file detected. The form
is pre-filled from a config file.
40
00:02:38,231 --> 00:02:41,795
Open Storage and database.
It's already filled in.
41
00:02:41,835 --> 00:02:46,912
MariaDB, user nextcloud, the password,
database nextcloud, and host db.
42
00:02:46,952 --> 00:02:52,822
The Nextcloud image wrote that config file
from the settings in your compose file.
43
00:02:52,862 --> 00:02:55,168
So there's nothing to type here.
44
00:02:56,441 --> 00:03:00,778
Above it, create the admin account.
A name, and a long password.
45
00:03:00,818 --> 00:03:03,211
This account runs the whole server.
46
00:03:04,426 --> 00:03:09,181
One thing before you click Install. Nextcloud
trusts the address you install from.
47
00:03:09,221 --> 00:03:12,163
I opened this page by the
server's network address,
48
00:03:12,203 --> 00:03:14,326
the one my laptop and phone will use.
49
00:03:14,366 --> 00:03:18,478
Install from a different address,
and other devices get an error later.
50
00:03:18,518 --> 00:03:20,623
I'll show you that error at the end.
51
00:03:21,916 --> 00:03:22,891
Install.
52
00:03:27,116 --> 00:03:30,468
It's installed, and it offers
some recommended apps.
53
00:03:30,508 --> 00:03:33,664
Calendar, Contacts, Mail,
Office, Notes and Talk.
54
00:03:33,704 --> 00:03:36,404
You don't need any of them to store files,
55
00:03:36,444 --> 00:03:39,770
and each one can be added
later from the Apps page.
56
00:03:41,030 --> 00:03:42,222
So, Skip.
57
00:03:46,804 --> 00:03:50,640
A welcome window. Skip
its intro, and close it.
58
00:03:51,333 --> 00:03:55,239
And that's a working Nextcloud.
You could start uploading now.
59
00:03:55,279 --> 00:03:59,695
But the compose file left two jobs
undone, and Nextcloud reports both,
60
00:03:59,735 --> 00:04:01,390
if you know where to look.
61
00:04:02,642 --> 00:04:05,472
Open Administration
settings, then Overview.
62
00:04:05,512 --> 00:04:09,712
Here, Nextcloud checks itself and
lists what it isn't happy with.
63
00:04:09,752 --> 00:04:11,865
A fresh install always has a few.
64
00:04:11,905 --> 00:04:15,062
Most of these are about
https, which comes later,
65
00:04:15,102 --> 00:04:17,516
when the server goes on the internet.
66
00:04:18,771 --> 00:04:22,333
This one is the first job.
Transactional file locking.
67
00:04:22,373 --> 00:04:25,801
The database is used for
transactional file locking.
68
00:04:25,841 --> 00:04:29,176
To enhance performance,
please configure memcache.
69
00:04:30,428 --> 00:04:35,467
File locking is how Nextcloud stops two
saves to the same file from colliding.
70
00:04:35,507 --> 00:04:40,155
Right now those locks go into the
database. Redis is meant to hold them.
71
00:04:40,195 --> 00:04:43,411
And Redis is running. The
compose file started it.
72
00:04:43,451 --> 00:04:48,009
But nothing told Nextcloud it's there.
The app section never names it.
73
00:04:49,292 --> 00:04:51,399
It's a blue note, so nothing is broken.
74
00:04:51,439 --> 00:04:54,851
But you're running a Redis
container that does nothing at all.
75
00:04:56,083 --> 00:04:57,809
Now Basic settings.
76
00:05:01,126 --> 00:05:03,621
Background jobs. AJAX is selected.
77
00:05:03,661 --> 00:05:08,468
That means Nextcloud runs one job
each time someone loads a page.
78
00:05:08,508 --> 00:05:12,122
Nobody on a page, no jobs.
And these jobs matter.
79
00:05:12,162 --> 00:05:18,053
They empty old files out of the trash
and old versions, and send notifications.
80
00:05:19,327 --> 00:05:21,256
Cron is the recommended setting.
81
00:05:21,296 --> 00:05:25,564
It runs the jobs every five minutes,
whether anyone is looking or not.
82
00:05:25,604 --> 00:05:30,672
But something on the server has to start
it. And nothing in this compose file does.
83
00:05:30,712 --> 00:05:32,066
That's the second job.
84
00:05:33,327 --> 00:05:34,311
Here's the fix.
85
00:05:34,351 --> 00:05:39,087
Both changes come from the examples
folder of the same GitHub project.
86
00:05:39,127 --> 00:05:43,727
First, give the app section one more
line. REDIS_HOST, equals redis.
87
00:05:43,767 --> 00:05:46,388
That's the name of the Redis container.
88
00:05:46,428 --> 00:05:50,004
When it's set, the image
switches Redis on by itself.
89
00:05:50,044 --> 00:05:52,870
Second, add a fourth service, called cron.
90
00:05:52,910 --> 00:05:56,555
It uses the same Nextcloud
image, and the same volume.
91
00:05:56,595 --> 00:06:01,127
But instead of the web server, it
runs a script called cron dot sh.
92
00:06:01,167 --> 00:06:04,510
That runs the background
jobs every five minutes.
93
00:06:05,848 --> 00:06:10,543
And one more change while you're in
the file. Put a version on the image.
94
00:06:10,583 --> 00:06:12,683
Plain nextcloud means the latest.
95
00:06:12,723 --> 00:06:16,121
Nextcloud can't skip a major
version when it updates,
96
00:06:16,161 --> 00:06:20,661
so a server on latest can be pulled
too far ahead and refuse to start.
97
00:06:20,701 --> 00:06:25,980
I use thirty five, apache, on both services,
and move it up one version at a time,
98
00:06:26,020 --> 00:06:26,928
when I choose.
99
00:06:29,431 --> 00:06:33,028
Save the file, and run docker
compose up, dash d, again.
100
00:06:33,068 --> 00:06:36,925
Docker makes a new Nextcloud
container with the new setting,
101
00:06:36,965 --> 00:06:39,523
and starts the cron container beside it.
102
00:06:39,563 --> 00:06:40,627
The volumes stay.
103
00:06:40,667 --> 00:06:45,083
So the install, the admin account
and any files are all still there.
104
00:06:46,362 --> 00:06:48,198
Back to Basic settings.
105
00:06:51,910 --> 00:06:57,229
The cron container runs every five
minutes, so I'll wait for its first run,
106
00:06:57,269 --> 00:06:58,055
and reload.
107
00:06:59,655 --> 00:07:02,188
Cron is selected now,
and I never clicked it.
108
00:07:02,228 --> 00:07:06,935
The first time the cron script runs,
Nextcloud switches the setting over by itself.
109
00:07:06,975 --> 00:07:08,805
The background jobs are running.
110
00:07:10,059 --> 00:07:11,141
And the Overview.
111
00:07:14,271 --> 00:07:18,119
The file locking note is gone.
Nextcloud is using Redis now.
112
00:07:18,159 --> 00:07:22,720
What's left is mostly about https,
and that comes with a reverse proxy,
113
00:07:22,760 --> 00:07:25,118
when the server goes on the internet.
114
00:07:25,158 --> 00:07:26,842
That's a video of its own.
115
00:07:28,097 --> 00:07:33,284
Last, the error I promised. This
server has a second network address.
116
00:07:33,324 --> 00:07:36,809
Here's the same Nextcloud,
opened by that one.
117
00:07:38,050 --> 00:07:43,295
Access through untrusted domain. Nextcloud
only answers to the addresses it trusts.
118
00:07:43,335 --> 00:07:48,262
After a setup page install, that's the
one you installed from, plus localhost.
119
00:07:48,302 --> 00:07:52,122
Any other name, like a domain
you add later, gets this page.
120
00:07:53,401 --> 00:07:57,352
To add one, run one occ command
through the app container.
121
00:07:57,392 --> 00:07:59,692
It's on the card, and on the page.
122
00:07:59,732 --> 00:08:04,440
Adding NEXTCLOUD TRUSTED DOMAINS to
the compose file now won't do it.
123
00:08:04,480 --> 00:08:09,296
The image only reads that during an
install done from the file itself.
124
00:08:11,180 --> 00:08:11,334
So.
125
00:08:11,374 --> 00:08:16,639
Take the compose file from Nextcloud's
GitHub page, and fill in the two passwords.
126
00:08:16,679 --> 00:08:18,580
Run docker compose up, dash d,
127
00:08:18,620 --> 00:08:22,527
and finish the setup page from
the address you'll really use.
128
00:08:22,567 --> 00:08:27,638
Then add what the file leaves out. The
Redis line on the app. A cron container.
129
00:08:27,678 --> 00:08:32,272
And a version on the image. The whole
file is on the page linked below.