Nextcloud Docker - move DB and data to NAS mount

Hi all.
I want to run Nextcloud Docker container on my Cloud-Server.
Space is a bit limited here for me, and as I expect that the NC Data and the Database will get quite big over time, I want to put those files on an NFS share of my storrage-system.

How needs docker-compose.yaml to be modified so I can store:

  • my files on NFS-Share mounted to /data/nextcloud/files
  • my DB on NFS-Share mounted to /data/nextcloud/db

I tried the following config without succsess:

version: '2'

volumes:
  nextcloud:
  db:

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

  app:
    image: nextcloud
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - /data/nextcloud/files:/var/www/html
    restart: always

I can see that ā€œsomeā€ files appear on the NAS (NFS) share ā€¦ but not all of them. Hence the startup will fail ā€¦

whatā€™s missing? and why you think itā€™s missing?

Hi, sorry for the delay ā€¦

Ok, this is what the Nextcloud path/files looks like when I use the parameters from above:

3rdparty  AUTHORS  console.php  COPYING  cron.php  index.html  index.php  occ  public.php  remote.php  robots.txt  status.php  version.php

And this is what the Nextcloud path/files looks like when I use the ā€˜nextcloud:/var/www/htmlā€™ volume:

3rdparty  AUTHORS  console.php  core      custom_apps  index.html  lib  ocm-provider  ocs-provider  remote.php  robots.txt  status.php  version.php
apps      config   COPYING      cron.php  data         index.php   occ  ocs           public.php    resources   settings    themes

Youā€™ll notice a lot more sub-dirs/files. #
Now ā€¦ why ?

is there anything in the logs docker logs nextcloud?
are the file in the container present? docker exec nextcloud ls -l /var/www/html

Well thereā€™s nothing in the logs that offers any hint on what went wrong:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
[Sun Feb 10 15:19:26.056683 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.14 configured -- resuming normal operations
[Sun Feb 10 15:19:26.057565 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

But when you try to open the home-page, you get:

Warning: require_once(/var/www/html/lib/versioncheck.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 36

Fatal error: require_once(): Failed opening required '/var/www/html/lib/versioncheck.php' (include_path='.:/usr/local/lib/php') in /var/www/html/index.php on line 36

And you get this error simply because the dir/files are not present in the volume. And yes, the files are present in the containerā€¦

The problem here seems that - for some reason - the volume is not ready when the Dockerfile (inside the container) tries to copy ā€œcertainā€ files to the dest. location ā€¦ or has some permission problems ā€¦ but there is no clue/hint in any logs ā€¦

Ok ā€¦ after reading this: https://github.com/moby/moby/issues/17470 and this: https://github.com/moby/moby/issues/21728 I think I found the reason why those files do not appear in the volumes.
But that would put the whole nextcloud-docker thing in jeopardy over its general usability ā€¦
I mean ā€¦ if all changes getting discarded how could you have a workin DB inside a volume/bind-mount ?

Still my orininal question remains: I need to store the apps/data and DB on a NFS-share ā€¦ how can this be achived ?

is the folder /data/nextcloud/files on the host empty?
the rsync in line 47 is responsible for copy the nextcloud file"in place" at first container start.

As a former NFS sysadmin, I strongly recommend that you donā€™t do that. If you want HA (High Availability) for your Nextcloud database and data, then you should have RAID in the Nextcloud server itself. Donā€™t put the Nextcloud database or data on an NFS mount, especially if itā€™s Linux NFS. Linux NFS isnā€™t as robust as Solaris NFS. Iā€™ve administered both professionally. In my experience, once too much strain was placed on Linux NFS, it cracked under pressure, and itā€™s very hard to debug. There was little active development on Linux NFS. At least you should test very thoroughly, placing a heavy simulated load on it, before you trust it.

Please donā€™t allow Linux NFS to be a point of failure for your Nextcloud server.

Donā€™t ā€œcheap outā€ on your Nextcloud server. If you need RAID, then dang it, give your Nextcloud server proper RAID (or maybe use Network-attached storage at the block level, not the NFS level, if you really want to kick it up a notch).

iā€™m not sure. but i think you donā€™t need that in your docker-compose file. you map the container folders to folders on your host. instead of using the volumes.

maybe you want to change this to:

volumes:
   - /data/nextcloud/files:/var/www/html/data
   - /data/nextcloud/config:/var/www/html/config
   - /data/nextcloud/custom_apps:/var/www/html/custom_apps
   - /data/nextcloud/themes:/var/www/html/themes

with this only the files that need to be persistent are store on the hosts filesystem. and you only need to put /data/nextcloud/files to the nfs share. because thatā€™s the folder with your files. all other folders wonā€™t grow that much.
and i also wouldnā€™t put the database on the nfs share. normally the database isnā€™t that large.

1 Like

This is an older post however this help me resolve my issues mounting data to nfs. I had problems with the general statement:

volumes:

  • /data/nextcloud/files:/var/www/html

to:

volumes:

  • /data/nextcloud/files:/var/www/html/data
  • /data/nextcloud/config:/var/www/html/config
  • /data/nextcloud/custom_apps:/var/www/html/custom_apps
  • /data/nextcloud/themes:/var/www/html/themes

breaking out the volumes as you indicated seem to make things run a lot smoother for me. Thanks