Nextcloud MySQL Container constantly restarting

Hello all,

I have done a system update: Ubuntu 21.10. to 22.04.1 LTS.
After the first reboot, the Nextcloud was still accessible in the browser. Therefore, I exclude the update as a source of error.

Afterwards I updated Docker manually and updated my containers:

cd /media/cloud/nextcloud
docker-compose pull
docker-compose stop
docker-compose rm
docker-compose up -d
docker-compose.yml
version: '3.8'

networks:
 nextcloud:

services:
  nextcloud:
    image: nextcloud:24
    container_name: nextcloud
    networks:
      - nextcloud
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - ${NEXTCLOUD_ROOT}/html:/var/www/html
      - ${NEXTCLOUD_ROOT}/data:/srv/nextcloud/data
    depends_on:
      - mysql
      - redis
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS='${NEXTCLOUD_FQDN}'
      - NEXTCLOUD_DATA_DIR=/srv/nextcloud/data
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_HOST=nextcloud-mysql
      - REDIS_HOST=nextcloud-redis
    restart: unless-stopped

  mysql:
    image: mysql:8
    container_name: nextcloud-mysql
    command: --upgrade=FORCE
    restart: unless-stopped
    volumes:
      - ${NEXTCLOUD_ROOT}/mysql-lib-old:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    networks:
      - nextcloud

  redis:
    image: redis:7
    container_name: nextcloud-redis
    networks:
      - nextcloud
    restart: unless-stopped`

At the time of the first container update (and before) no image versions were specified (nextcloud:24, mysql:8, …)
But I am sure, it was installed nextcloud v23.0.0.10 and MySQL v8.0.27. (never MySQL v5!)

Since that time the mysql containers could not start and are in a constant restart loop:

$ docker-compose ps
     Name                    Command                 State              Ports
--------------------------------------------------------------------------------------
nextcloud         /entrypoint.sh apache2-for ...   Up           127.0.0.1:8080->80/tcp
nextcloud-mysql   docker-entrypoint.sh --upg ...   Restarting
nextcloud-redis   docker-entrypoint.sh redis ...   Up           6379/tcp

When I look at the log, this is displayed:

[...]
nextcloud-mysql | 2022-08-19 14:30:55+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
nextcloud-mysql | 2022-08-19 14:30:55+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
nextcloud-mysql | 2022-08-19 14:30:55+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
nextcloud-mysql | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
nextcloud-mysql | 2022-08-19T14:30:55.544494Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
nextcloud-mysql | 2022-08-19T14:30:55.545309Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 1
nextcloud-mysql | 2022-08-19T14:30:55.549156Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
nextcloud-mysql | 2022-08-19T14:30:55.598243Z 1 [ERROR] [MY-012526] [InnoDB] Upgrade is not supported after a crash or shutdown with innodb_fast_shutdown = 2. This redo log was created with MySQL 8.0.27, and it appears logically non empty. Please follow the instructions at http://dev.mysql.com/doc/refman/8.0/en/upgrading.html
nextcloud-mysql | 2022-08-19T14:30:55.598260Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
nextcloud-mysql | 2022-08-19T14:30:56.066932Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
nextcloud-mysql | 2022-08-19T14:30:56.067345Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
nextcloud-mysql | 2022-08-19T14:30:56.067403Z 0 [ERROR] [MY-010119] [Server] Aborting
nextcloud-mysql | 2022-08-19T14:30:56.068641Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30)  MySQL Community Server - GPL.
nextcloud-mysql exited with code 1

Since the container is constantly restarting, you can’t follow the mysql instructions because you can’t access the DB.

How do I get the container out of the continuous loop so that it does not terminate?

How do I solve the problem?

Thank you very much!

Why do you think that? Those instructions are not to use after the upgrade, but before that and you don’t need to connect to the database to follow the instructions. The documentation also mentions how you should upgrade using Docker containers, but it mentions an other image. It is mysql/mysql-server not mysql:8. The process is probably the same for bot images or at least similar.

Does it mean you use a newer MySQL version? If it does, start the container with the odler version again and follow the mentioned instructions to properly upgrade MySQL. Make sure you have a backup and you properly stop the old container when you need to stop it. If the container does not have time to do that, the data files can be corrupted or in state that cannot be automatically upgraded.