OwnServa
Storage · Installation guide

How to install Nextcloud with Docker on Ubuntu

Install Nextcloud with Docker Compose, MariaDB and Redis. Configure storage, HTTPS, your first administrator account and backups.

Run Nextcloud on a private Docker network with MariaDB for application data and Redis for locking. This guide ends with a working administrator login and a file-upload check. Plan around 2 CPU cores, 4 GB RAM and storage sized for your files as an OwnServa starting estimate.

Before you start

Complete server preparation, Docker and HTTPS. Reserve cloud.example.com and loopback port 8081 on a server where that port is free. If another service uses it, change the host-side port and your proxy together. Your Nextcloud login is independent of your OwnServa account.

mkdir -p ~/selfhosted/nextcloud
cd ~/selfhosted/nextcloud
umask 077
openssl rand -hex 32

Run the last command twice. Save the two different outputs in .env:

DB_PASSWORD=REPLACE_WITH_FIRST_RANDOM_SECRET
DB_ROOT_PASSWORD=REPLACE_WITH_SECOND_RANDOM_SECRET
NEXTCLOUD_DOMAIN=cloud.example.com

Configure the database and storage

Save this as compose.yaml. MariaDB creates the nextcloud database and its dedicated user on the first start of an empty database volume. The root password is separate from the application password.

services:
  db:
    image: mariadb:11.4
    restart: unless-stopped
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:?set DB_ROOT_PASSWORD}
      MARIADB_DATABASE: nextcloud
      MARIADB_USER: nextcloud
      MARIADB_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD}
    volumes:
      - database:/var/lib/mysql
    healthcheck:
      test: [CMD, healthcheck.sh, --connect, --innodb_initialized]
      interval: 10s
      timeout: 5s
      retries: 12
  redis:
    image: redis:7-alpine
    restart: unless-stopped
  app:
    image: nextcloud:apache
    restart: unless-stopped
    ports:
      - "127.0.0.1:8081:80"
    environment:
      MYSQL_HOST: db
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD}
      REDIS_HOST: redis
      NEXTCLOUD_TRUSTED_DOMAINS: localhost ${NEXTCLOUD_DOMAIN}
      OVERWRITEPROTOCOL: https
      OVERWRITECLIURL: https://${NEXTCLOUD_DOMAIN}
    volumes:
      - nextcloud:/var/www/html
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
  cron:
    image: nextcloud:apache
    restart: unless-stopped
    entrypoint: /cron.sh
    volumes:
      - nextcloud:/var/www/html
    depends_on:
      - app
volumes:
  database:
  nextcloud:

Do not add a host port to db or redis. The application reaches them by service name. Changing .env later does not change an existing MariaDB user's password; rotate credentials in the database and application together.

Start Nextcloud and configure HTTPS

chmod 600 .env
sudo docker compose config --quiet
sudo docker compose up -d
sudo docker compose ps
sudo docker compose logs --tail=60 app db

Add a Caddy site for cloud.example.com pointing to 127.0.0.1:8081, using the HTTPS instructions. Before completing the installer, determine the Docker gateway used by the host proxy:

sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}' "$(sudo docker compose ps -q app)"

Add TRUSTED_PROXIES: "THE_GATEWAY_IP" to the app.environment block, replacing the placeholder with that output, and run sudo docker compose up -d. Trust only your proxy's address, not every internet address.

Create your first administrator

Open https://cloud.example.com. Choose a unique administrator username and strong password, then complete the installer. The database fields should already be populated by the environment settings. If shown, use database name nextcloud, user nextcloud, the DB_PASSWORD value and host db. Leave the data directory at /var/www/html/data for this volume layout.

Sign in with the administrator you just created. Choose Cron in Administration settings → Basic settings for background jobs. Create a separate everyday user, upload a small file and download it again. Configure outgoing email and test it before depending on recovery messages.

Back up and update

Preserve the nextcloud volume, a consistent MariaDB backup and your .env file. During a maintenance window, stop writes before taking a coordinated backup; a copied file directory without its matching database is incomplete. Check Nextcloud's required upgrade sequence before changing image versions, and keep app and cron on the same release.

Troubleshooting

  • Untrusted domain: check NEXTCLOUD_TRUSTED_DOMAINS against the exact browser hostname.
  • Database connection refused: confirm db is healthy and MYSQL_HOST is db, not localhost.
  • Redirect loops or insecure URL warnings: confirm HTTPS forwarding, OVERWRITEPROTOCOL and the exact trusted proxy IP.
  • First page is slow: inspect sudo docker compose logs --tail=100 app; the initial installation can take time.

Official references

This is an OwnServa walkthrough using the project's container interface. Review the Nextcloud container documentation, installation wizard and system requirements before choosing pinned production versions.

Written by OwnServa. Check the official release notes before updating, keep independent backups and test a restore before relying on your installation.

Get it done for you.

Want a hand setting up Nextcloud? Create an OwnServa account and tell us what you want to run. We can discuss the server, installation and first-time setup with you.

We’ll confirm the scope, availability and any costs before work begins.