# Self-host Nextcloud with Postgres and Redis

> Nextcloud file sync, sharing and collaboration on the official image with a bundled Postgres database and a Redis cache for file locking. The admin account is created on first start with the generated password.

- Page: https://levelrail.com/templates/nextcloud-postgres/
- JSON: https://levelrail.com/templates/nextcloud-postgres.json
- Category: Storage
- Licence: AGPL-3.0-or-later (Network copyleft (AGPL) license)
- Source: https://github.com/nextcloud/server
- Upstream docs: https://docs.nextcloud.com/server/latest/admin_manual/installation/

## Requirements
- Memory: about 1.5 GiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 17.11-alpine

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| db | postgres | 17.11-alpine | none | pgdata -> /var/lib/postgresql/data |
| nextcloud | nextcloud | 33.0.10-apache | 80 | nextcloud_html -> /var/www/html |
| redis | redis | 7.4.7-alpine | none | redis_data -> /data |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| db | POSTGRES_DB | preset |
| db | POSTGRES_PASSWORD | generated |
| db | POSTGRES_USER | preset |
| nextcloud | NEXTCLOUD_ADMIN_PASSWORD | generated |
| nextcloud | NEXTCLOUD_ADMIN_USER | preset |
| nextcloud | POSTGRES_DB | preset |
| nextcloud | POSTGRES_HOST | preset |
| nextcloud | POSTGRES_PASSWORD | generated |
| nextcloud | POSTGRES_USER | preset |
| nextcloud | REDIS_HOST | preset |

## Deploy

### CLI

```bash
levelrail-cli templates install nextcloud-postgres --name my-nextcloud-postgres
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain db=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/nextcloud-postgres/install \
  -d '{
    "name": "my-nextcloud-postgres"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## First run
1. Sign in as admin with the generated admin password from the app secrets. First start takes a minute while the database is prepared.

## Questions

### Can I deploy Nextcloud with Postgres and Redis on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for Nextcloud with Postgres and Redis, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image postgres:17.11-alpine, nextcloud:33.0.10-apache, redis:7.4.7-alpine is what you deploy there.

Self-host Nextcloud with Postgres and Redis, Nextcloud with Postgres and Redis docker compose file, deploy Nextcloud with Postgres and Redis on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
