Deploying Nextcloud with MariaDB and Redis in Docker: A Step-By-Step Guide

· 2 min read
Deploying Nextcloud with MariaDB and Redis in Docker: A Step-By-Step Guide

NextCloud is a self-hosted productivity platform that covers everything from file sharing and collaboration to syncing your digital life. With MariaDB as the database and Redis for caching, you can boost its performance. In this guide, I’ll show you how to get this stack running on Docker.


What You’ll Need

Before we start, ensure you have the following:

  • A VPS or local machine with Docker and Docker Compose installed.
  • Basic knowledge of Docker and command-line operations.
  • A little excitement about hosting your own Nextcloud instance! 🚀

The Docker Compose Setup

Here’s the Docker Compose file to deploy Nextcloud with MariaDB and Redis:

services:  
  db:  
    image: mariadb  
    restart: unless-stopped  
    command: >  
      --transaction-isolation=READ-COMMITTED  
      --binlog-format=ROW  
      --innodb-file-per-table=1  
      --skip-innodb-read-only-compressed  
    volumes:  
      - db:/var/lib/mysql  
    env_file:  
      - db.env  

  redis:  
    image: redis  
    restart: always  
    command: redis-server --requirepass your_redis_password  

  app:  
    image: nextcloud:latest  
    restart: unless-stopped  
    ports:  
      - 8999:80  
    links:  
      - db  
      - redis  
    volumes:  
      - nextcloud:/var/www/html  
    environment:  
      - MYSQL_HOST=db  
      - REDIS_HOST_PASSWORD=your_redis_password  
    env_file:  
      - db.env  
    depends_on:  
      - db  
      - redis  

volumes:  
  db:  
  nextcloud:  

What Does This Do?

  • MariaDB (db):
    • Acts as the database backend for Nextcloud.
    • Stores all user data, file metadata, and configurations.
  • Redis:
    • Provides caching to improve Nextcloud’s performance.
    • Secured with a password for extra protection.
  • Nextcloud (app):
    • Your core application container, connected to both MariaDB and Redis.
    • Exposed on port 8999 (visit it via http://<your-server-ip>:8999).

Step 1: Set Up Environment Variables

Create a file named db.env in the same directory and define your MariaDB credentials:

MYSQL_ROOT_PASSWORD=secure_root_password  
MYSQL_DATABASE=nextcloud  
MYSQL_USER=nextcloud_user  
MYSQL_PASSWORD=secure_user_password  

Replace the placeholders with secure values.


Step 2: Deploy the Stack

Fire up the containers with:

docker-compose up -d  

Docker will:

  1. Pull the necessary images.
  2. Create and start the containers.
  3. Connect Nextcloud to MariaDB and Redis.

Step 3: Configure Nextcloud

  1. Navigate to http://<your-server-ip>:8999.
  2. Fill out the setup wizard:
    • Database type: MySQL/MariaDB
    • Database host: db
    • Database name: nextcloud
    • Username: nextcloud_user
    • Password: The one from your db.env.
  3. Connect Redis for caching:
    • Use redis as the hostname and your_redis_password as the password.

Step 4: Secure Your Instance

While this gets your Nextcloud instance running, don’t forget to:

  • Enable HTTPS: Use a reverse proxy like Caddy or Traefik to secure your site.
  • Regular Backups: Use docker exec commands or volume snapshots to back up your data.

Wrapping Up

Congratulations! 🎉 You’ve successfully deployed your own Nextcloud server with MariaDB and Redis using Docker. This setup gives you:

  • Blazing-fast performance thanks to Redis caching.
  • Robust storage with MariaDB.
  • Complete control over your data.

Now, you’re ready to sync files, collaborate with your team, and manage your digital life.

Happy Deployment. 🚀