Nextcloud on a VPS: your own file storage, with Docker Compose

The short answer: Nextcloud is an open-source program that gives you your own “Drive”: files, calendar and contacts, on a server of yours. It installs on a VPS with Docker Compose in two containers (Nextcloud and a database), behind a proxy with https. You need root access and it is not for shared hosting.

It is third-party software: the customer installs it, updates it and keeps the backups. Our support does not install or repair it (see How far our support goes). Beforehand, have Docker set up: Installing Docker and Docker Compose.

The compose file

In a folder of its own, for example ~/nextcloud, create the file compose.yaml. Change the two passwords to long, different, randomly generated ones:
services:
db:
image: mariadb:10.11
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: (a long password)
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: (another long password)
app:
image: nextcloud:apache
restart: unless-stopped
depends_on:
- db
ports:
- "127.0.0.1:8080:80"
volumes:
- nextcloud:/var/www/html
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: (the second password)
NEXTCLOUD_TRUSTED_DOMAINS: cloud.your-domain
OVERWRITEPROTOCOL: https
volumes:
db:
nextcloud:

1 Start it: docker compose up -d inside the folder. The first time it downloads the images and takes a while.
2 The address stays local only (port 127.0.0.1:8080): on purpose, so it is reached from outside only through the proxy with https. Set it up as in Nginx as a reverse proxy in front of a container and HTTPS for a container.
3 Open your domain’s address in the browser and create the administrator. Choose a strong password: this user can do everything.

What you must not forget

Topic What to do
Backups The files and the database live in two “volumes”. Copy both, and test the restore. See Docker: volumes and backups.
Updating Change the image and bring it up again, but one major version at a time: Nextcloud does not support skipping versions. See Updating a Docker application without losing data.
Space The users’ files take the VPS disk. Nextcloud does not warn you before the disk fills.
Security Only https in sight; updates up to date; strong passwords; and the rest in Running Docker on a VPS safely.
This stores people’s files. A Nextcloud without backups, updates or https is a risk to whoever put what is theirs there. If you do not want to maintain a server, a service built for this may be the better idea.
If you only need somewhere to put files to share, first see whether what you already have is enough. Nextcloud pays off when you need to control where the data lives.

The containers start but the address does not open? Open a ticket with the output of docker compose ps (without the passwords).

Open a support ticket

SEE ALSO

Installing Docker and Docker Compose on a VPS

Docker Compose: an application with its database

Nginx as a reverse proxy in front of a container

Updating a Docker application without losing data

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from $7.61/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?