When to use this stack
Nextcloud is a self-hosted platform for file sync, sharing, calendars, contacts and collaborative documents. Its official container runs Apache and PHP, but a working installation also needs a database and a cache. This stack uses MariaDB 11.4 for the database and Redis 7 for file locking and the memory cache, and it waits for both to pass their health checks before Nextcloud starts. Nextcloud 35 is pinned by its major tag, so a routine docker compose pull does not change the application version unexpectedly. The web port is bound to 127.0.0.1, so the installation is reachable only from the host until you add a reverse proxy.
Use this stack when you want to replace a consumer cloud drive for a family, a small team or your own devices, and you can keep the server updated and backed up. Do not use it when you cannot provide HTTPS, because desktop and mobile clients send login credentials and file contents over the network. Do not use it when you only need to share a few files once, since a simple file server or a temporary link service is easier to run. Also avoid it on a very small machine with less than 2 GB of RAM, because Nextcloud previews and the database both need memory during synchronization.
docker-compose.yml
services:
db:
image: mariadb:11.4
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_DATABASE: ${MARIADB_DATABASE}
MARIADB_USER: ${MARIADB_USER}
MARIADB_PASSWORD: ${MARIADB_PASSWORD}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
redis:
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
nextcloud:
image: nextcloud:35-apache
restart: unless-stopped
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
environment:
MYSQL_HOST: db
MYSQL_DATABASE: ${MARIADB_DATABASE}
MYSQL_USER: ${MARIADB_USER}
MYSQL_PASSWORD: ${MARIADB_PASSWORD}
NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER}
NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD}
NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_TRUSTED_DOMAINS}
REDIS_HOST: redis
ports:
- "127.0.0.1:8080:80"
volumes:
- nextcloud_data:/var/www/html
volumes:
db_data:
redis_data:
nextcloud_data:MARIADB_ROOT_PASSWORD=CHANGE_ME_ROOT_PASSWORD
MARIADB_DATABASE=nextcloud
MARIADB_USER=nextcloud
MARIADB_PASSWORD=CHANGE_ME_DB_PASSWORD
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=CHANGE_ME_ADMIN_PASSWORD
NEXTCLOUD_TRUSTED_DOMAINS="localhost cloud.example.com".env
MARIADB_ROOT_PASSWORD=CHANGE_ME_ROOT_PASSWORD
MARIADB_DATABASE=nextcloud
MARIADB_USER=nextcloud
MARIADB_PASSWORD=CHANGE_ME_DB_PASSWORD
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=CHANGE_ME_ADMIN_PASSWORD
NEXTCLOUD_TRUSTED_DOMAINS="localhost cloud.example.com"Start and verify
# 1. Validate the compose file and the variable substitution
docker compose config --quiet
# 2. Start the stack in the background
docker compose up -d
# 3. db and redis should show "(healthy)", nextcloud should show "Up"
docker compose ps
# 4. Watch the first installation; it can take a minute or two
docker compose logs -f nextcloud
# 5. Status endpoint through the loopback port (expected: JSON with "installed":true)
curl -fsS http://127.0.0.1:8080/status.php
# 6. Confirm that Redis is used for the cache after login
docker compose exec redis redis-cli pingLog in at http://localhost:8080 with the administrator account from .env. Then open Settings, Administration, Overview and resolve any warnings it lists, because the overview reports missing indices, background job settings and HTTPS problems.
Production checklist
- Terminate HTTPS in a reverse proxy and add your public domain to NEXTCLOUD_TRUSTED_DOMAINS. Without this, Nextcloud refuses requests from that domain.
- Set OVERWRITEPROTOCOL=https in the nextcloud environment when TLS ends at the proxy, so links and redirects use https.
- Switch background jobs to system cron. Run the cron.php script every five minutes from the host with docker compose exec -u www-data nextcloud php cron.php.
- Keep the database and Redis unpublished. Only the nextcloud service should reach them on the internal network.
- Use unique passwords for the root, application and administrator accounts, and enable two-factor authentication for administrators.
- Back up db_data and nextcloud_data together, and dump the database with mariadb-dump while the stack runs, because copying a live data directory alone can corrupt the database.
- Check that the host has enough disk space for previews and version history, which grow over time.
- Pin the Nextcloud major version and upgrade one major version at a time, as the Nextcloud documentation requires.
Common problems
- Symptom: the browser shows “Access through untrusted domain”. Cause: the address used in the browser is not in NEXTCLOUD_TRUSTED_DOMAINS. Fix: add the exact host name, including any port, to the variable and run docker compose up -d again.
- Symptom: the first start loops and the log says it cannot connect to the database. Cause: the database was initialized earlier with different credentials, or MariaDB needed more time than the start period allowed. Fix: make the MARIADB_* values match the existing volume, or wait for db to report healthy before checking nextcloud.
- Symptom: the admin overview warns about a missing memory cache. Cause: REDIS_HOST is missing from the environment, or the Redis service is not healthy. Fix: confirm the variable and check docker compose ps. Redis in this stack has no password, so no further settings are required.
- Symptom: links and redirects point to http while users access the site through HTTPS. Cause: the reverse proxy terminates TLS but Nextcloud does not know that. Fix: set OVERWRITEPROTOCOL=https and forward the standard X-Forwarded headers from the proxy.
- Symptom: the admin overview warns that background jobs run via AJAX. Cause: the cron job is not configured. Fix: set up the host cron entry from the production checklist and switch the setting to Cron.
Variations
- PostgreSQL instead of MariaDB: replace the db service with postgres:16, set the Nextcloud POSTGRES_* variables described in the official image documentation, and keep the same Redis service. Use this if you already run PostgreSQL for other applications.
- Caddy for HTTPS: add a Caddy service on the same network that proxies your domain to nextcloud:80. Remove the loopback port mapping so that only Caddy receives traffic from the internet.
- Larger installations: move nextcloud_data to a separate disk or an S3-compatible object storage backend, configured through the Nextcloud documentation. Keep the database on its own volume so that backups stay simple.
Questions
Why does Nextcloud need Redis?
Redis holds the memory cache and file locking data. Without it, Nextcloud falls back to slower database-based locking, and the web interface feels sluggish when several clients sync at once.
Why is MariaDB 11.4 used?
MariaDB 11.4 is a long-term support release with the transaction isolation and row-based binary logging settings that the Nextcloud documentation recommends. The compose file sets those options in the command section.
What happens to my data if I remove the containers?
Your files and database stay in the named volumes nextcloud_data and db_data. Running docker compose down keeps them, but docker compose down -v deletes them permanently.
Adapt this stack
Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.
Open in builderRelated stacks
Paperless-ngx with PostgreSQL and Redis
Run Paperless-ngx 2.20 document archive with PostgreSQL 16 and Redis in Docker Compose. OCR language setup, loopback-only port, backups and a consume folder.
Reduced Supabase Stack (Postgres + PostgREST)
Reduced self-hosted Supabase-style stack: supabase/postgres plus PostgREST for a REST API. Pinned tags, healthcheck, loopback port, official guide link.
Django + PostgreSQL + Celery
Run a Django app with Gunicorn, PostgreSQL 16, Redis 7 as the Celery broker and a Celery worker in Docker Compose, with healthchecks and a production checklist.
Laravel + PostgreSQL + Redis
Run a Laravel app on Apache with PostgreSQL 16 and Redis 7 in Docker Compose, with a Dockerfile, queue and cache settings, volumes and a production checklist.
Browse more Automation, AI & Self-Hosted stacks or the full library.