Setup Nextcloud with Redis using Docker

Overview

We’ll go through the steps how to Setup Nextcloud with Redis using Docker. For this process we’ll be using Docker compose and build a stack to deploy at once Nextcloud Docker container with MariaDB and Redis all together.

Requirements to setup Nextcloud with Redis:

  • Docker installed and running on the host server(Install Docker)
  • Docker compose installed(Install Docker Compose)

Redis is an open source object cache server that can be used as a database cache in order to improve database performance. By default Nextcloud doens’t have database cache(can be configured though) and without database cache, the Nextcloud performance can dwindle(be really slow in other words) but when Redis is added into the play, it can drastically improve Nextcloud performance. Redis also have an official Docker container, which we’ll be using in this docker compose file.

Setup Nextcloud with Redis using Docker

In the following paragraph, the Docker compose configuration is provided here and we’ll cover the configuration what it does:

version: '3'

volumes:

  nextcloud:

  db:

services:

  db:

    image: mariadb

    restart: always

    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-file-per-table=1 --skip-innodb-read-only-compressed

    volumes:

      - db:/var/lib/mysql

    environment:

      - MYSQL_ROOT_PASSWORD=somerootpassword

      - MYSQL_PASSWORD=somemysqlpassword

      - MYSQL_DATABASE=db

      - MYSQL_USER=mysqluser

  redis:

    image: redis

    restart: always

    command: redis-server --requirepass someredispassword

  app:

    image: nextcloud

    restart: always

    ports:

      - 8080:80

    links:

      - db
      - redis

    volumes:

      - nextcloud:/var/www/html

    environment:

      - MYSQL_PASSWORD=somemysqlpassword

      - MYSQL_DATABASE=db

      - MYSQL_USER=mysqluser

      - MYSQL_HOST=db

      - REDIS_HOST_PASSWORD=someredispassword

    depends_on:

      - db

      - redis

The approach we’re using to deploy the containers is that we’re specifying each container as a service, and each service will have it’s own mounted data volume on the host machine. This method allows us to easier connect containers and make it so that some containers depend on others to function properly.

Overview of the docker compose yaml file:

  • version: ‘3’ // Docker compose version
  • volumes: // defining which containers will have mounted volumes
  • nextcloud:
  • db:
  • services: // defining which containers are services
  • db: // database service for nextcloud
  • image: mariadb // Official docker of mariadb server
  • restart: always // argument to restart container always on any kind of issue
  • command: –transaction-isolation=READ-COMMITTED –binlog-format=ROW –innodb-file-per-table=1 –skip-innodb-read-only-compressed // command to run on MariaDB to configure database table format. Otherwise you may experience Inno_DB refuses to write error
  • volumes: // db:/var/lib/mysql
  • **environment: // **Environment variables where we specify the database credentials
  • - MYSQL_ROOT_PASSWORD=somerootpassword
  • - MYSQL_PASSWORD=somemysqlpassword
  • - MYSQL_DATABASE=db
  • - MYSQL_USER=mysqluser
  • **redis: // **redis service defined
  • **image: redis // **Official Redis Docker image
  • **restart: always // **argument to restart container always on any kind of issue
  • **command: redis-server –requirepass someredispassword // ** argument to pass-through to redis  command to set a redis password
  • **app: // **defined nextcloud as service
  • **image: nextcloud // **defined the official nextcloud docker image
  • **restart: always // **argument to restart container always on any kind of issue
  • **ports: - 8080:80 // **argument to set what ports to be exposed in order to access the Nextcloud
  • links: - db -redis // defined a redis link and database link for Nextcloud to use and store data(in the link we just need to set the database service name we previously set for MariaDB container)
  • **volumes: - nextcloud:/var/www/html // ** environment variable to set a persistent volume and store data on the host machine
  • **environment: //  **Environment variables where we specify the database credentials(these must match the MariaDB credentials from above and provide the redis password)
  • - MYSQL_PASSWORD=somemysqlpassword
  • - MYSQL_DATABASE=db
  • - MYSQL_USER=mysqluser
  • - MYSQL_HOST=db
  • - REDIS_HOST_PASSWORD=someredispassword
  • **depends_on: // **Environment variable where we specify dependency for Nextcloud
  • - db
  • - redis

Deploy Docker compose file

How to deploy this stack:

Via terminal and text editor, we’ll be creating a new directory in which we’ll store the docker-compose-yml and in that file we’ll paste in our yaml config. You can see in the pictures bellow how I did it:

Setup Nextcloud with Redis using Docker

Note - mind the indentation and make sure that each line is in a correct indentation position.

Once we created the docker-compose file and saved the changes in it with our yaml configuration, to deploy the stack, run the following command while still located in the directory where our docker-compose file is located:

docker-compose up -d

The successful results should look like this:

Setup Nextcloud with Redis using Docker

You can check with command “docker ps -a” if the containers are present and running.

When you confirmed that the deployment was successful, double check in you browser if you can access the Nextcloud via IP address and the exposed port. You should be able to see the starting page of Nextcloud in where it asks to create an admin account and to complete the installation.

Setup Nextcloud with Redis using Docker

Summary

To review what we have covered in this post - process how to setup Nextcloud with Redis using Docker. With docker compose, we deployed a stack of docker containers in a single deployment in which we configured to deploy Nextcloud that’ll be using Redis as an database object cache for it’s MariaDB database in order to increase the Nextcloud performance. To also clarify this is not a standard method, it’s just one of many ways to create this Docker stack and connect these services and I find this to be one of the simplest methods to write a docker compose for this setup.

Thank you for your time…