What's the right way to upgrade Nextcloud on Docker?

I haven’t been able to find a definitive guide to upgrading Nextcloud on Docker. I was hoping you could just update the Docker container and it would handle the rest, but I just tried that and it didn’t work.

What is the right way to upgrade to a new version of Nextcloud on Docker?

Nextcloud version : Upgrading from 23.0.4 to 23.0.5
Operating system and version : Docker version 20.10.16 on Ubuntu 20.04
Container tag: nextcloud:23-apache

The issue you are facing: Web UI stays in “Maintenance mode” forever.

Is this the first time you’ve seen this error? (Y/N): Yes (first time I’ve tried to upgrade minor versions since installing on Docker)

Steps to replicate it:

  1. Rebuild Docker container
  2. Start new container
  3. Open Nextcloud in browser
  4. Observe Maintenance Mode screen

The output of your Nextcloud log in Admin > Logging: Can’t get there

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

<?php
$CONFIG = array (
  'overwrite.cli.url' => 'https://<my URL>',
  'htaccess.RewriteBase' => '/',
  'trusted_domains' =>
  array (
    0 => '127.0.0.1',
    1 => 'localhost',
    2 => '<internal IP>',
    3 => '<external IP>',
    4 => '<my domain>',
  ),
  <various mail_ settings>
  'overwriteprotocol' => 'https',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'redisr',
    'port' => 6379,
    'password' => '...',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'passwordsalt' => '...',
  'secret' => '...',
  'datadirectory' => '/ncdata',
  'dbtype' => 'mysql',
  'version' => '23.0.5.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'mariadbn',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '...',
  'installed' => true,
  'instanceid' => '...',
  'loglevel' => 0,
  'maintenance' => false,
  'default_phone_region' => 'US',
);

The output of your Apache/nginx/system log in /var/log/____:
Docker logs say:

Configuring Redis as session handler
Initializing nextcloud 23.0.5.1 ...
Upgrading nextcloud from 23.0.4.1 ...
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Turned on maintenance mode
Updating database schema
Updated database
Disabled incompatible app: breezedark
Disabled incompatible app: bruteforcesettings
Disabled incompatible app: calendar
Disabled incompatible app: contacts
Disabled incompatible app: deck
Disabled incompatible app: documentserver_community
Disabled incompatible app: event_update_notification
Disabled incompatible app: files_antivirus
Disabled incompatible app: mail
Disabled incompatible app: maps
Disabled incompatible app: onlyoffice
Disabled incompatible app: quota_warning
Disabled incompatible app: spreed
Disabled incompatible app: tasks
Disabled incompatible app: twofactor_nextcloud_notification
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 467814792 bytes) in /var/www/html/lib/private/Installer.php on line 300
Configuring Redis as session handler
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.17.4. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.17.4. Set the 'ServerName' directive globally to suppress this message
[Sat May 21 12:14:01.668742 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.53 (Debian) PHP/8.0.19 configured -- resuming normal operations
[Sat May 21 12:14:01.668826 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
172.20.15.5 - - [21/May/2022:12:14:07 -0500] "GET /svg/core/actions/clippy?color=fff&v=2 HTTP/1.0" 503 11962 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36"
(there's more, but doesn't look relevant)

Sounds like a bug.

Updating a Docker-based Nextcloud is documented at GitHub - nextcloud/docker: â›´ Docker image of Nextcloud , and it does sound like you are doing it right (pull / rebuild a new image, destroy old container, start new container).

Could this line in the log file be the key to the problem?

That seems like a lot of memory to allocate … do I have too many apps loaded or something?

I had the same problem with upgrading from 23.0.3 to 23.0.4. Were you able to resolve it?

Not exactly; more like the problem just went away. I restored everything from backup, retried the upgrade, and it all worked fine. I really have no idea what was different the second time. Frustrating.

Just tried to upgrade from 24.0.3.2 to 24.0.4.1; same problem. This happens nearly every time I upgrade.

I see tons of posts regarding “PHP Fatal error: Allowed memory size of xxx bytes exhausted”, but the solutions either don’t work or don’t apply to the Docker image.

Surely there’s a solution to this?