Docker and nfs troubles

I’m trying to migrate nextcloud from a jail on my FreeNAS server to docker running on Ubuntu LTS, but I’m having a lot of trouble. I’m trying to incrementally get things working then add the next piece. Right now I’m stuck trying to get MariaDB working with it’s permanent data in a nfs share. I got this all working with the nextcloud_db volume commented out. With it added the nextcloud setup give the following error:

Error

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away

Here’s the setup details:

FreeNAS 11.3-U2 lots of storage, ram, and processor
Share 1: All dirs, maproot user -> root, maproot group -> wheel, Ubuntu host is the only IP allowed
Share 2: maproot user -> root, maproot group -> wheel, Ubuntu host is the only IP allowed

Ubuntu 18.04.4 LTS running on a Pi4 2GB
Docker version 19.03.6, build 369ce74a3c

version: '3.5'
services:
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - nextcloud_db:/var/lib/mysql
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=database
      - MYSQL_USER=user
  app:
    image: nextcloud
    ports:
      - 80:80
    links:
      - db
    volumes:
      - nextcloud_html:/var/www/html
      - nextcloud_data:/var/www/html/data
    restart: always

volumes:
    nextcloud_html:
        driver: local
        driver_opts:
            type: "nfs"
            o: "addr=sharehost,nolock,soft,rw"
            device: ":/Share1/nextcloud_html"
    nextcloud_data:
        driver: local
        driver_opts:
            type: "nfs"
            o: "addr=sharehost,nolock,soft,rw"
            device: ":/Share2"
    nextcloud_db:
        driver: local
        driver_opts:
            type: "nfs"
            o: "addr=sharehost,nolock,soft,rw"
            device: ":/Share1/nextcloud_db"

I’ve seen this problem several times, so I think this will not work. A database needs a high performance access to its data files. Not sure what the exact problem is with nfs, maybe the latency, maybe missing features.

I am afraid database files and nolock won’t play nice together.

I strongly suggest to use nfs4 instead of nfs3. We used to use nfsv4 and nfsv4.1 for a long time with good results. We had a containerized Postgres database in our testing environment. Our application was tested in other datacenters that used nfs3; they had all sorts of problems.

Hint: a volume declaration is not updated when changed. If you apply changes to your volumes, you need to stop the stack, manually remove the volumes with “docker volume rm” and start your stack again in order to let docker (re-)create the volumes with the changed configuration.

Since MariaDB is a MySQL fork, the same limitation will apply to it:

Using NFS with MySQL

You should be cautious when considering whether to use NFS with MySQL. Potential issues, which vary by operating system and NFS version, include the following:

    MySQL data and log files placed on NFS volumes becoming locked and unavailable for use. Locking issues may occur in cases where multiple instances of MySQL access the same data directory or where MySQL is shut down improperly, due to a power outage, for example. NFS version 4 addresses underlying locking issues with the introduction of advisory and lease-based locking. However, sharing a data directory among MySQL instances is not recommended.

    Data inconsistencies introduced due to messages received out of order or lost network traffic. To avoid this issue, use TCP with hard and intr mount options.

    Maximum file size limitations. NFS Version 2 clients can only access the lowest 2GB of a file (signed 32 bit offset). NFS Version 3 clients support larger files (up to 64 bit offsets). The maximum supported file size also depends on the local file system of the NFS server. 

Using NFS within a professional SAN environment or other storage system tends to offer greater reliability than using NFS outside of such an environment. However, NFS within a SAN environment may be slower than directly attached or bus-attached non-rotational storage.

If you choose to use NFS, NFS Version 4 or later is recommended, as is testing your NFS setup thoroughly before deploying into a production environment. 

Source: https://dev.mysql.com/doc/refman/8.0/en/disk-issues.html

1 Like