Multiple NFS mounts on docker compose

observations:

  • version ‘3.4’ is used even though there is zero benefit compared to 2.4
  • more volumes declared than used, actualy only 2 nfs baked volumes used
  • db service has key command: twice
  • values in the volumes section are quoted while unquoted in the services declarations ← inconsistence
  • no tags provided.

Personal preferences:

  • I would skip driver: local for volumes as its the default driver
  • I would use key/value based environment declarations, instead of a yaml sequence
  • I would set a specific tag for the images ← no suprise breakage caused by major updates

I am surprised the compose file declaration config you shared actualy works like this. I would have assumed that duplicate keys raise an error and prevent execution.

Note: a volume once created by docker-compose is immutable. Configuration changes will NOT be applied to the volume declaration. In order to update the volume declaration, stop the containers, remove the volumes you need updated and redeploy your compose configuration to let them be re-created with the new values.

update:
I modified your compose file, removed some things irrelevant to me and added others:

version: '2.4'

volumes:
  nextcloud:
    driver_opts:
      type: nfs 
      o: addr=random-ip,nfsvers=4
      device: :/volume3/docker/nextcloud/data
  db:
    driver_opts:
      type: nfs 
      o: addr=random-ip,nfsvers=4
      device: :/volume3/docker/nextcloud/db

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

  app:
    image: nextcloud:23.0-apache
    container_name: nextcloud_app
    restart: always
    ports:
      - 18082:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
    environment:
      NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_TRUSTED_DOMAINS}
      NEXTCLOUD_ADMIN_USER: nextcloud
      NEXTCLOUD_ADMIN_PASSWORD: nextcloud
      MYSQL_HOST: db
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: password

I had to remove the volumes you added underneath /var/www/html, it indeed caused a permissions issue (which doesn’t realy make sense to me).

Replace ${NEXTCLOUD_TRUSTED_DOMAINS} in the compose file above either with the hostname of your dockerhost, or with the full qualified domain name you want to use to access your nc instance. By adding these three adition parameters the setup will be skipped all along and you can directly login into nc. There is should be no need to chown the nfs exports, as both images start as root, fix ownership and then start the main process with dropped priviliges.

Update: appearently the subfolder mount stuff realy breaks things. The odd part is that the folders inside the nfs share are correct, but it still doesn’t work. I consider this rather a problem with the nextcloud image itself, than realy a docker problem. You might want to try your luck in the nextcloud forum, I assume the number of nextcloud forum users that actualy run it in docker are magnitudes higher than docker users that actualy run nextcloud. I am personaly not using nextcloud and can’t tell you why it missbehaves like it does.

1 Like