Internal server error after restarting docker-compose

I had a running NextCloud installation using docker-compose. After stopping and restarting the docker stack I experience an internal server error:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Nextcloud version: 24
Operating system and version : Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal

I have tried to update the fingerprint of the database and to activate maintenance mode but none of these work.

I have found the following error message:

Next Doctrine\DBAL\Exception\TableNotFoundException: An exception occurred while executing a query: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist in /var/www/html/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:47

It sounds like it may not be connected to your database. What were the exact commands you used to stop and start it?

You can also try looking at the docker container logs. There’s usually something helpful in there.

To stop nextcloud I have used
docker-compose down
To start it I have used
docker-compose -f docker-compose.yml up -d

Maybe, it is necessary to first activate maintenance mode of NextCloud before stopping containers?

you will find more details regarding the issue in the log of your application container e.g. docker logs nextcloud-app look for the issues and if you need more help post this logs and your docker-compose file as well.

Thank you for the hint. Looking at the logs I was not able to figure out why the “Internal Server Error” occured. I have restored NextCloud from a backup that I am running every second day so no data is lost.

1 Like

docker logs nextcloud

Configuring Redis as session handler
[24-Mar-2024 05:41:52] NOTICE: fpm is running, pid 1
[24-Mar-2024 05:41:52] NOTICE: ready to handle connections
172.19.0.7 -  24/Mar/2024:05:41:58 +0000 "GET /index.php" 500
NOTICE: PHP message: PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(181): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object( in /var/www/html/lib/private/DB/Connection.php on line 64
NOTICE: PHP message: PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(181): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object( in /var/www/html/lib/private/DB/Connection.php on line 64
172.19.0.7 -  24/Mar/2024:05:42:02 +0000 "GET /index.php" 500
NOTICE: PHP message: PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(181): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object( in /var/www/html/lib/private/DB/Connection.php on line 64
NOTICE: PHP message: PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(181): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object( in /var/www/html/lib/private/DB/Connection.php on line 64
172.19.0.7 -  24/Mar/2024:05:42:05 +0000 "GET /index.php" 500
172.19.0.7 -  24/Mar/2024:05:42:06 +0000 "GET /index.php" 500

@peekaboot Your database is not running or otherwise not functioning/reachable by Nextcloud.

Every time the first time nextcloud runs, it runs very well, however, once the nextcloud container restart, or reboot, it will run into the error. I googled this issue and found many people encountered the same issue no one can find the reason.

Every time the first time nextcloud runs, it runs very well, however, once the nextcloud container restart, or reboot, it will run into the error.

What about your database container? That’s where this problem is. It’s not Nextcloud itself (unless someone really really odd is going on).

I googled this issue and found many people encountered the same issue no one can find the reason.

That’s just because it’s a relatively generic error that happens anytime someone’s database server is offline or unreachable.

I suggest checking the state of your database container and/or posting:

  • your Docker Compose file
  • the output of occ config:list system from Nextcloud

Hello jtr !
Thank you for your reply. I think I found the solution and finally work fine.
Perhaps because I’m a newbie of docker,I run the following command :

docker-compose -f nextcloud_docker.yml down
docker-compose -f nextcloud_docker.yml up

and this is my docker compose file:

nextcloud:
    depends_on:
      - mysql
      #- redis

    image: nextcloud:22-fpm-alpine

    container_name: nextcloud
    environment:
      - PUID=0
      - PGID=0
      - MYSQL_HOST=mysql
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=nextcloud
      - REDIS_HOST=redis
      - APACHE_PORT=8001

    volumes:
      - /root/docker_data/nextcloud/html:/var/www/html

    restart: unless-stopped

what the issue of the command is the “down” command stop and removes the container, the configuration is stored persistent in the /root/docker_data/nextcloud/html/config,
and when it runs with docker compose up, the newly created container’s network or config differs from previously created’s, then causes the error,
The right command is

docker-compose -f nextcloud_docker.yml restart

Your suggestions gave me great tips. Thank you!