Unable to use Nextcloud in docker container after container restart

I am using the latest lsio docker image.
Nextcloud version (eg, 20.0.5):
Operating system and version (eg, Ubuntu 20.04): Alpine 3.14
Apache or nginx version (eg, Apache 2.4.25): nginx/1.20.2
PHP version (eg, 7.4): 7.4.26 and 8.0.13

The issue you are facing:
I’m able to get through the setup of Nextcloud and start using it. However, once I need to restart the docker container for any reason (historically an update) I’m no longer able to use Nextcloud. I’m greeted with a generic server error once everything spins back up.

I understand the error points to permissions issues, but here’s where I’m stuck. In my docker-compose.yml if I specify PUID/PGID as 1000 (the user I’m running docker as on the box) I first get a generic, text only, server error message. I have to chown -R www-data:www-data /path/to/nextcloud/config in order for the Nextcloud branded error to show, which has the request ID I use to find the error in the logs.

If I set PUID/PGID to 33 (www-data) the plain text error is the only thing I get and I can’t get the Nextcloud branded page with the request ID to show even if I muck with permissions. Also, nothing ends up hitting the error log at all.

Is this the first time you’ve seen this error? (Y/N): No

The output of your Nextcloud log in Admin > Logging:

N/A, unable to log in.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'datadirectory' => '/data',
  'instanceid' => '$instanceid',
  'passwordsalt' => '$passwordsalt',
  'secret' => '$secret',
  'trusted_domains' =>
  array (
        0 => '',
        1 => 'cloud.ncflake',
        2 => 'nextcloud.ncflake',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => 'https://nextcloud.ncflake',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '$DBUSER',
  'dbpassword' => '$DBPASSWORD',
  'installed' => true,
  'allow_local_remote_servers' => true,
  'filesystem_check_changes' => 1,

Relevant entry in /log/nginx/error.log:

2022/01/13 16:46:47 [error] 409#409: *5 FastCGI sent in stderr: "PHP message: {"reqId":"67IYfrMQd2mElShdOQhi","level":3,"time":"2022-01-13T23:46:47+00:00","remoteAddr":"","user":"--","app":"PHP","method":"GET","url":"/","message":"touch(): Utime failed: Permission denied at /config/www/nextcloud/lib/private/Config.php#248","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0","version":"","exception":{"Exception":"Error","Message":"touch(): Utime failed: Permission denied at /config/www/nextcloud/lib/private/Config.php#248","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/config/www/nextcloud/lib/private/Config.php","line":248,"function":"touch"},{"file":"/config/www/nextcloud/lib/private/Config.php","line":138,"function":"writeData","class":"OC\\Config","type":"->"},{"file":"/config/www/nextcloud/lib/private/SystemConfig.php","line":131,"function":"setValue","class":"OC\\Config","type":"->"},{"file":"/config/www/nextcloud/lib/private/legacy/OC_Util.php","line":1119,...PHP message: {"reqId":"67IYfrMQd2mElShdOQhi","level":3,"time":"2022-01-13T23:46:47+00:00","remoteAddr":"","user":"--","app":"PHP","method":"GET","url":"/","message":"fopen(/config/www/nextcloud/config/config.php): Failed to open stream: Permission denied at /config/www/nextcloud/lib/private/Config.php#249","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0","version":"","exception":{"Exception":"Error","Message":"fopen(/config/www/nextcloud/config/config.php): Failed to open stream: Permission denied at /config/www/nextcloud/lib/private/Config.php#249","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/config/www/nextcloud/lib/private/Config.php","line":249,"function":"fopen"},{"file":"/config/www/nextcloud/lib/private/Config.php","line":138,"function":"writeData","class":"OC\\Config","type":"->"},{"file":"/config/www/nextcloud/lib/private/SystemConfig.php","
2022/01/13 16:46:47 [error] 409#409: *5 FastCGI sent in stderr: "PHP message: {"reqId":"67IYfrMQd2mElShdOQhi","level":3,"time":"2022-01-13T23:46:47+00:00","remoteAddr":"","user":"--","app":"PHP","method":"GET","url":"/","message":"fopen(/config/www/nextcloud/data/nextcloud.log): Failed to open stream: No such file or directory at /config/www/nextcloud/lib/private/Log/File.php#84","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0","version":""}" while reading upstream, client:, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: "cloud.ncflake"

My docker-compose.yml:

version: "2.1"
    image: lscr.io/linuxserver/nextcloud:php8
    container_name: nextcloud
      - PUID=1000
      - PGID=1000
      - TZ=America/Boise
      - /home/doc_brown/compose/nextcloud/config:/config
      - /mnt/unraid/nextcloud/data:/data
      - 2443:443
    restart: unless-stopped
    image: lscr.io/linuxserver/mariadb
    container_name: nextcloud-mariadb
      - db:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud_db_user
      - TZ=America/Boise
    restart: unless-stopped

Hi @ncflake

I don’t have any experience with Nextcloud in Docker or specifically the linuxserver image, so I can’t help you directly with your issue. But as far as I know the whole PGID and GUID thing is specific to the linuxserver.io images. So in case you don’t get any answers here, you could also try to ask your question at their forums… https://discourse.linuxserver.io/. And here is a link to how PGID and GUID work in general. Maybe it is of any help, if you didn’t already read it.