Nextcloud Self-Hosted Cloud

Posted on Aug 28, 2024
tl;dr: Building a self hosted cloud with Nextcloud

Building a self-hosted cloud with Nextcloud and Docker

I often alternate between Android and Iphone. I like both platforms and every couple of years, I’ll switch to the other.

One problem that switching platforms creates is I have thousands of photos in iCloud and thousands of photos in Google photos.

I want to have them all located in one place and act as a backup of all my photos for the last 25 years.

Enter Nextcloud self-hosted cloud

I’ve seen Nextcloud for years on Youtube and have always thought about giving it a try. I have several options in my home lab to choose from for a Nextcloud host. I picked an old desktop machine running Linux Mint with plenty of storage space for the photos.

Using Docker for my Nextcloud self-hosted cloud

Docker and docker-compose are fantastic for efficient deployments of services. I often use AI to quickly create docker-compose files and Grok is very good at making docker-compose.yaml files where I just had to add in my username and password to the file and it deployed Nextcloud perfectly the first time. Here is the one I used.

version: '3.3'

services:
  db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /data1/nextcloud/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud:latest
    restart: always
    ports:
      - 8080:80
    environment:
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
    volumes:
      - /data1/nextcloud/config:/var/www/html/config/
      - /data1/nextcloud/crontab:/var/spool/cron/crontabs
      - /data1/nextcloud/data:/var/www/html
    depends_on:
      - db

  redis:
    image: redis:alpine
    restart: always

  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /data1/nextcloud/watchtower:/config
    environment:
      - WATCHTOWER_CLEANUP=true
      - WATCHTOWER_SCHEDULE=0 0 4 * * *  # Run at 4 AM every day
    restart: unless-stopped

volumes:
  db:
  nextcloud:
Notes
  1. To preserve the config.php file, you put it on volumes that are not in the container. That way you can keep Nextcloud updated to the latest version and you preserve the files that have your particular configuration settings.
  2. You also, of course, map the volume of the files and photos and content stored in Nextcloud to a volume on your host or other storage that doesn’t change with container upgrades.
  3. Nextcloud requires a cron job run on /var/www/html/config.php. It is set to every 5 minutes. I had some issues with it running too much because I set up Google integration to pull over all the photos and Gdrive files. To better manage the cron job, I put the cron job on the Host Linux Mint system. See “Docker Cron Jobs for Containers” post.