Nextcloud 21 install with Docker Compose on Ubuntu 20.04

Self-Hosting Nov 4, 2020

Last Updated: 18th July 2021

WARNING: Due to a Nextcloud bug, the mariadb:latest tag is not compatible with Nextcloud. To fix use the MariaDB docker tag mariadb:10.5.

Nextcloud is open source software that allows anyone to self-host their own private storage.

This guide is aimed at Ubuntu 20.04 but it will work with most Linux distros.

What we'll do

  • Deploy a Nextcloud instance using docker
  • Fix the configuration, to authenticate using the mobile app

Prerequisites

Caddy v2 Reverse Proxy Simple Setup Guide
What is Caddy? Caddy has a wide range of use cases including: * Web Server * Reverse Proxy * Sidecar Proxy * Load Balancer * API Gateway * Ingress Controller * System Manager * Process Supervisor * Task Scheduler Today we will be installing and setting up Caddy as a Reverse Proxy. This w…
Setting up Nginx Proxy Manager with Docker Compose
What we’ll do: * Install docker * Setup Nginx Proxy Manager This guide is aimed at Ubuntu/Debian systems. Why:To run multiple services over the same port a reverse proxy service is required. Nginx Proxy Manager [https://nginxproxymanager.com/] is a WebUI frontend for thepopular Nginx [https://www.nginx.com/…

Install

  1. Grab a coffee ☕
  1. Update Linux
    sudo apt update && sudo apt upgrade
  1. Make sure you have docker-compose installed
    sudo apt install docker-compose
  1. Create your Nextcloud Directory

sudo mkdir nextcloud && cd nextcloud

  1. Create docker-compose.yaml file

Use the following as a template:
sudo nano docker-compose.yaml

version: '3' 

services:
  nextclouddb:
    image: mariadb:latest
    container_name: nextcloud-mariadb
    volumes:
      - ./data/mysql:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    networks:
      default:
        ipv4_address: 10.10.10.4
    environment:
      - MYSQL_ROOT_PASSWORD=CHANGEME
      - MYSQL_PASSWORD=CHANGEME2
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    restart: unless-stopped
  
  nextcloudapp:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
      default:
        ipv4_address: 10.10.10.5
    volumes:
      - ./data/html:/var/www/html
      - ./data/config:/var/www/html/config
      - ./data/apps:/var/www/html/custom_apps
      - ./data/data:/var/www/html/data
      - ./data/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped

networks:
  default:
    external:
      name: dockernet

Using external storage? Check out this docker-compose.yaml

Replace:
10.10.10.4 and 10.10.10.5: Use a relevant docker network IP
CHANGEME: A nice and strong password

To create a Docker Network:
sudo docker network create --driver=bridge --subnet=10.10.10.0/24 --gateway=10.10.10.1 dockernet

  1. Start the docker containers
    sudo docker-compose up -d
  1. Set up the Reverse Proxy

Caddy Example:

nextcloud.example.com {
  reverse_proxy 10.10.10.5:80
  header {
        Strict-Transport-Security max-age=31536000;
        X-Content-Type-Options nosniff;
        X-XSS-Protection "1; mode=block;"
        X-Robots-Tag none;
        X-Frame-Options SAMEORIGIN;
        Referrer-Policy no-referrer;
  }
}
Nginx Proxy Manager Example
  1. Head to the WebUI

Create your admin account
Select MySQL/MariaDB and enter the details used in the docker-compose file
nextcloud-setup

You should now be welcomed to Nextcloud:

Nextcloud Welcome Screen
  1. Fix the "Grant access" issue with the Nextcloud App. This is an issue with the Reverse Proxy using HTTPS.

sudo nano $HOME/nextcloud/data/config/config.php

Add: 'overwriteprotocol' => 'https',
Just before 'trusted_domains' =>

It should look similar to this:
nextcloud-configphp

You should now be able to sign in using the Nextcloud App.

All done!

Comments

Tags