Nextcloud Docker - move DB and data to NAS mount

docker
nas

#1

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 …


#2

what’s missing? and why you think it’s missing?


#3

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 ?


#4

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


#5

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 …


#6

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 ?


#7

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.


#8

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).


#9

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.