Failed to install Nextcloud with docker-compose

Hello and thank you for this community!

I try to install using docker-compose.

My docker-compose.yml looks like this

version: '3.4'

services:
  db:
    container_name: nextcloud_db
    image: postgres
    restart: unless-stopped
    volumes:
      - /data/cloud-storage/nextcloud-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user

  app:
    container_name: nextcloud_app
    image: nextcloud:18
    restart: unless-stopped
    ports:
      - 1234:80
    volumes:
      - /data/cloud-storage/nextcloud-data:/var/www/html
    environment:
      - POSTGRES_HOST=db
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/nextcloud_admin_password
      - NEXTCLOUD_ADMIN_USER_FILE=/run/secrets/nextcloud_admin_user
    depends_on:
      - db
    secrets:
      - nextcloud_admin_password
      - nextcloud_admin_user
      - postgres_db
      - postgres_password
      - postgres_user

volumes:
  db:
    name: nextcloud-db
  nextcloud:
    name: nextcloud-data

secrets:
  nextcloud_admin_password:
    file: ./nextcloud_admin_password.txt # put admin password to this file
  nextcloud_admin_user:
    file: ./nextcloud_admin_user.txt # put admin username to this file
  postgres_db:
    file: ./postgres_db.txt # put postgresql db name to this file
  postgres_password:
    file: ./postgres_password.txt # put postgresql password to this file
  postgres_user:
    file: ./postgres_user.txt # put postgresql username to this file

I also made sure all the secret files are present.

When I start the services and visit the installations website, I would expect the user credentials to be prefilled already. However, they are not:

Even when I fill out the credentials myself, I only get failure messages.

What am I doing wrong?

Thank you in advance for your help!

isn’t that POSTGRES_DB and shouldn’t it be ‘default’?

Thank you very much, @Reiner_Nippes!

Actually, I referred to these instructions:
https://hub.docker.com/_/nextcloud/ (section Docker Secrets), also here (https://github.com/nextcloud/docker#docker-secrets) – this is the same instruction but the link already points to the Docker Secrets section.

I’m unsure what POSTGRES_DB should be, but why do you think it should be ‘default’?

ok. i wasn’t aware that there is a POSTGRES_DB_FILE.

did you check the the logs of both containers? docker logs db and docker logs app

yes, I checked that. I found nothing suspicious, but I can post the logs here.

Also, I tried to log into the db container and check the db myself with psql. However, I failed doing so because I couldn’t enter the db (but maybe that was my fault). I can post that here as well.

Thanks again for your help!

So here are the promised logs:

db:
$ docker logs nextcloud_db

PostgreSQL Database directory appears to contain a database; Skipping initialization

2020-06-05 09:39:10.904 UTC [1] LOG:  starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-06-05 09:39:10.904 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-06-05 09:39:10.904 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2020-06-05 09:39:11.446 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-06-05 09:39:12.040 UTC [29] LOG:  database system was shut down at 2020-06-05 09:38:59 UTC
2020-06-05 09:39:12.258 UTC [1] LOG:  database system is ready to accept connections

app:

$ docker logs nextcloud_app
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.23.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.23.0.3. Set the 'ServerName' directive globally to suppress this message
[Fri Jun 05 09:39:14.376832 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured -- resuming normal operations
[Fri Jun 05 09:39:14.376879 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

So, there is one problem concerning the url (this was expectable, as it is not specified anywhere - however, this doesn’t seem to cause my issues.

The other thing is, that the db skipped the initialization as there was data already. Maybe this is a residual of a previous installation attempt which is now blocking me to enter the database? I could try and remove the data and see if it works then.

Otherwise, I tried to get inside the database with docker exec -it nextcloud_db /bin/bash and psql then, but I didn’t manage to log in. It should work with the same values as in my secret files, right?

I stopped my docker containers and cleaned the volumes before I started them again.

It seems, I got one step further, however, it is still not running.

The app logs now look like this:

$ docker logs nextcloud_app
Initializing nextcloud 19.0.0.12 ...
Initializing finished
New nextcloud instance
Installing with PostgreSQL database
starting nextcloud installation
PostgreSQL username and/or password not valid
 -> You need to enter details of an existing account.
retrying install...
Nextcloud was successfully installed
setting trusted domains…
An unhandled exception has been thrown:
PDOException: SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for table oc_appconfig in /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:88
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(88): PDO->query('SELECT * FROM "...')
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(908): Doctrine\DBAL\Driver\PDOConnection->query('SELECT * FROM "...')
#2 /var/www/html/lib/private/DB/Connection.php(194): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM "...', Array, Array, NULL)
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(200): OC\DB\Connection->executeQuery('SELECT * FROM "...', Array, Array)
#4 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(216): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/lib/private/AppConfig.php(331): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/lib/private/AppConfig.php(109): OC\AppConfig->loadConfigValues()
#7 /var/www/html/lib/private/AppConfig.php(287): OC\AppConfig->getApps()
#8 /var/www/html/lib/private/legacy/OC_App.php(883): OC\AppConfig->getValues(false, 'installed_versi...')
#9 /var/www/html/lib/private/Server.php(662): OC_App::getAppVersions()
#10 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#11 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#12 /var/www/html/lib/private/Server.php(1699): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#13 /var/www/html/lib/private/Server.php(853): OC\Server->getMemCacheFactory()
#14 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#15 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\App\\AppManag...')
#16 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\ServerContainer->query('OC\\App\\AppManag...')
#17 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#18 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OCP\\App\\IAppMan...')
#19 /var/www/html/lib/private/Server.php(1889): OC\ServerContainer->query('OCP\\App\\IAppMan...')
#20 /var/www/html/lib/private/legacy/OC_App.php(347): OC\Server->getAppManager()
#21 /var/www/html/lib/private/legacy/OC_App.php(114): OC_App::getEnabledApps()
#22 /var/www/html/lib/base.php(647): OC_App::loadApps(Array)
#23 /var/www/html/lib/base.php(1090): OC::init()
#24 /var/www/html/console.php(49): require_once('/var/www/html/l...')
#25 /var/www/html/occ(11): require_once('/var/www/html/c...')
#26 {main}

Next Doctrine\DBAL\Driver\PDOException: SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for table oc_appconfig in /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:90
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(908): Doctrine\DBAL\Driver\PDOConnection->query('SELECT * FROM "...')
#1 /var/www/html/lib/private/DB/Connection.php(194): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM "...', Array, Array, NULL)
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(200): OC\DB\Connection->executeQuery('SELECT * FROM "...', Array, Array)
#3 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(216): Doctrine\DBAL\Query\QueryBuilder->execute()
#4 /var/www/html/lib/private/AppConfig.php(331): OC\DB\QueryBuilder\QueryBuilder->execute()
#5 /var/www/html/lib/private/AppConfig.php(109): OC\AppConfig->loadConfigValues()
#6 /var/www/html/lib/private/AppConfig.php(287): OC\AppConfig->getApps()
#7 /var/www/html/lib/private/legacy/OC_App.php(883): OC\AppConfig->getValues(false, 'installed_versi...')
#8 /var/www/html/lib/private/Server.php(662): OC_App::getAppVersions()
#9 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#10 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#11 /var/www/html/lib/private/Server.php(1699): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#12 /var/www/html/lib/private/Server.php(853): OC\Server->getMemCacheFactory()
#13 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#14 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\App\\AppManag...')
#15 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\ServerContainer->query('OC\\App\\AppManag...')
#16 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#17 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OCP\\App\\IAppMan...')
#18 /var/www/html/lib/private/Server.php(1889): OC\ServerContainer->query('OCP\\App\\IAppMan...')
#19 /var/www/html/lib/private/legacy/OC_App.php(347): OC\Server->getAppManager()
#20 /var/www/html/lib/private/legacy/OC_App.php(114): OC_App::getEnabledApps()
#21 /var/www/html/lib/base.php(647): OC_App::loadApps(Array)
#22 /var/www/html/lib/base.php(1090): OC::init()
#23 /var/www/html/console.php(49): require_once('/var/www/html/l...')
#24 /var/www/html/occ(11): require_once('/var/www/html/c...')
#25 {main}

Next Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'SELECT * FROM "oc_appconfig"':

SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for table oc_appconfig in /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php:79
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(169): Doctrine\DBAL\Driver\AbstractPostgreSQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(145): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\PDOPgSql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'An exception oc...')
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(911): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOPgSql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT * FROM "...', Array)
#3 /var/www/html/lib/private/DB/Connection.php(194): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM "...', Array, Array, NULL)
#4 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(200): OC\DB\Connection->executeQuery('SELECT * FROM "...', Array, Array)
#5 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(216): Doctrine\DBAL\Query\QueryBuilder->execute()
#6 /var/www/html/lib/private/AppConfig.php(331): OC\DB\QueryBuilder\QueryBuilder->execute()
#7 /var/www/html/lib/private/AppConfig.php(109): OC\AppConfig->loadConfigValues()
#8 /var/www/html/lib/private/AppConfig.php(287): OC\AppConfig->getApps()
#9 /var/www/html/lib/private/legacy/OC_App.php(883): OC\AppConfig->getValues(false, 'installed_versi...')
#10 /var/www/html/lib/private/Server.php(662): OC_App::getAppVersions()
#11 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#12 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#13 /var/www/html/lib/private/Server.php(1699): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#14 /var/www/html/lib/private/Server.php(853): OC\Server->getMemCacheFactory()
#15 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#16 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OC\\App\\AppManag...')
#17 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\ServerContainer->query('OC\\App\\AppManag...')
#18 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#19 /var/www/html/lib/private/ServerContainer.php(124): Pimple\Container->offsetGet('OCP\\App\\IAppMan...')
#20 /var/www/html/lib/private/Server.php(1889): OC\ServerContainer->query('OCP\\App\\IAppMan...')
#21 /var/www/html/lib/private/legacy/OC_App.php(347): OC\Server->getAppManager()
#22 /var/www/html/lib/private/legacy/OC_App.php(114): OC_App::getEnabledApps()
#23 /var/www/html/lib/base.php(647): OC_App::loadApps(Array)
#24 /var/www/html/lib/base.php(1090): OC::init()
#25 /var/www/html/console.php(49): require_once('/var/www/html/l...')
#26 /var/www/html/occ(11): require_once('/var/www/html/c...')
#27 {main}AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.3. Set the 'ServerName' directive globally to suppress this message
[Fri Jun 05 12:13:04.820407 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.6 configured -- resuming normal operations
[Fri Jun 05 12:13:04.820448 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
10.99.0.1 - - [05/Jun/2020:12:13:23 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
10.99.0.1 - - [05/Jun/2020:12:14:48 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
10.99.0.1 - - [05/Jun/2020:12:16:24 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
10.99.0.1 - - [05/Jun/2020:12:16:27 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
10.99.0.1 - - [05/Jun/2020:12:27:35 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
10.99.0.1 - - [05/Jun/2020:12:37:44 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
[Fri Jun 05 12:58:46.547489 2020] [mpm_prefork:notice] [pid 1] AH00170: caught SIGWINCH, shutting down gracefully
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.2. Set the 'ServerName' directive globally to suppress this message
[Fri Jun 05 12:59:17.029878 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.6 configured -- resuming normal operations
[Fri Jun 05 12:59:17.029934 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
10.99.0.1 - - [05/Jun/2020:12:59:33 +0000] "GET / HTTP/1.0" 500 716 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"

And on the url I get

By the way, I also slightly changed my docker-compose file - in case that matters:

version: '3.4'

services:
  db:
    container_name: nextcloud_db
    image: postgres
    restart: unless-stopped
    volumes:
      - /data/cloud-storage/nextcloud-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user
  app:
    container_name: nextcloud_app
    image: nextcloud:18
    restart: unless-stopped
    ports:
      - 1431:80
    volumes:
      - /data/cloud-storage/nextcloud-data:/var/www/html
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS=<domain1> <domain2>
      - POSTGRES_HOST=db
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/nextcloud_admin_password
      - NEXTCLOUD_ADMIN_USER_FILE=/run/secrets/nextcloud_admin_user
    depends_on:
      - db
    secrets:
      - nextcloud_admin_password
      - nextcloud_admin_user
      - postgres_db
      - postgres_password
      - postgres_user

volumes:
  db:
    name: nextcloud-db
  nextcloud:
    name: nextcloud-data

secrets:
  nextcloud_admin_password:
    file: ./nextcloud_admin_password.txt # put admin password to this file
  nextcloud_admin_user:
    file: ./nextcloud_admin_user.txt # put admin username to this file
  postgres_db:
    file: ./postgres_db.txt # put postgresql db name to this file
  postgres_password:
    file: ./postgres_password.txt # put postgresql password to this file
  postgres_user:
    file: ./postgres_user.txt # put postgresql username to this file

What to do now?

Thank you once more for your time and patience!

something wrong with your secrets. sorry. can’t help you with this.

to check the postgres db:
docker exec db pg_isready -U postgres

and if you want to connect to your db:
docker exec -it db psql -U nextcloud (if your user is as well “nextcloud”.

Thanks for your answer, however, it had nothing to do with that.

My sercrets work fine and I also checked that a couple of times.

Actually, the line in my log you were referring to only states that the data base container wasn’t ready at the time the app container first tried to access it.

After the line you cited, the log says:

retrying install...
Nextcloud was successfully installed

which indicates, that the secrets are not the problem.

However, with the help of a friend and after many hours of debugging, we finally found the problem which is - at least somehow - related to that:

Somehow the nextcloud docker-scripts refuse to work properly, when the app has to wait for the database.

So I ensured that the database container is ready before the app container starts, using wiat-for-it (see my new docker-compose file below).

Doing so, everything works as expected.

Here’s the docker-compose file

version: '3.4'

services:
  db:
    container_name: nextcloud_db
    image: postgres:12.3
    restart: unless-stopped
    volumes:
      - /data/cloud-storage/nextcloud-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
    networks:
      - nextcloud
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user

  app:
    container_name: nextcloud_app
    image: nextcloud:19.0.0-apache
    restart: unless-stopped
    ports:
      - 1431:80
    volumes:
      - ./wait-for-it/wait-for-it.sh:/bin/wait-for-it.sh # necessary to ensure that database is ready first
      - ./nextcloud-config:/var/www/html/config
      - /data/cloud-storage/nextcloud-data:/var/www/html
    entrypoint: sh -c '/bin/wait-for-it.sh db:5432 --timeout=120 && /entrypoint.sh apache2-foreground'
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS=<domain 1> <domain 2>
      - POSTGRES_HOST=db
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/nextcloud_admin_password
      - NEXTCLOUD_ADMIN_USER_FILE=/run/secrets/nextcloud_admin_user
    depends_on:
      - db
    networks:
      - nextcloud
    secrets:
      - nextcloud_admin_password
      - nextcloud_admin_user
      - postgres_db
      - postgres_password
      - postgres_user

networks:
  nextcloud:

secrets:
  nextcloud_admin_password:
    file: ./nextcloud_admin_password.txt # put admin password to this file
  nextcloud_admin_user:
    file: ./nextcloud_admin_user.txt # put admin username to this file
  postgres_db:
    file: ./postgres_db.txt # put postgresql db name to this file
  postgres_password:
    file: ./postgres_password.txt # put postgresql password to this file
  postgres_user:
    file: ./postgres_user.txt # put postgresql username to this file

To use it, you have to make sure that wait-for-it is available in the corresponding folder.

1 Like

did you try healthcheck?

Thank you for the tip, @Reiner_Nippes!

I was really excited about your suggestion for healthcheck until I found this: https://github.com/peter-evans/docker-compose-healthcheck/issues/3. Therefore, healthcheck isn’t an option anymore.

However, it seems that Nextcloud developers tried to go for option 3 (Make your application resilient to database failure and able to retry it’s connection on startup) but failed to do so as my issue suggests.

I think it would be worth to file a bug report - what do you think?

you’ll find the installation of nextcloud here (for the fpm-alpine image):

it seams that the first run of occ maintenance isn’t cleanup properly. in a first try i would look if a config.php is created and delete it.

but of course it’s better to loop until the database comes available.

yes. you should open a git issue.

1 Like

@Spindoctor thank you for these posts. Very informative. I think I went down exactly the same road so I will try waiting for the database, too. Did you end up opening an issue and if so, can you link it here, please?

Actually, I came across this issue which suggests that one must let the postgres service create a different database (created by its entrypoint script) than the one used by the nextcloud app service… https://github.com/nextcloud/docker/issues/345

services:
  ...

  app:
    ...
    environment:
    - POSTGRES_DB=nextcloud


  db:
    ...
    environment:
    - POSTGRES_DB=postgres

That works for me without needing a waiting script.

Okay, the change above must have been a random fluke. It only worked once.

I decided to also introduce waiting like you suggest @Spindoctor but since I am running the fpm alpine image, I could not use the wait-for-it.sh script which needs bash. Instead I found this simple solution:

    entrypoint: sh -c "while !(nc -z db 5432); do sleep 1; done; /entrypoint.sh php-fpm"
1 Like

Thanks, worked for me!

It’s funny that it always worked on my laptop, but it doesn’t work on my NAS.

Maybe my laptop much faster than NAS.