Nextcloud with Docker - password authentication failed for user

I am deploying Nextcloud using the official image and postgres:13-alpine.

I’ve configured the Postgres container such that the username and password (note: this is not the actual password) nextcloud:gq48CHM2QVQ9VV8YrMMLDrehpHKx5U39jwFrVmYMxczXhA9PPeApVqySPDMQE9k2aqCAKhnbRFWezZBnarG99jzpJHPhaRvJy5A7 accesses a Postgres database named nextcloud. I have confirmed that this works by logging in to that Postgres instance using those credentials and it works.

I have configured the Nextcloud Docker container with these environment variables:

  • POSTGRES_PASSWORD: gq5A7 (the password above)
  • POSTGRES_USER: nextcloud
  • POSTGRES_DB: nextcloud
  • POSTGRES_HOST: nextcloud-postgres:5432 (I have verified the hostname and that it resolves.)
  • NEXTCLOUD_ADMIN_PASSWORD: another password of similar length and style to the Postgres password
  • NEXTCLOUD_ADMIN_USER: a username

but I get this error:

{
	"reqId": "1b9wPWL2w8zcnkYbpAPd",
	"level": 3,
	"time": "2021-04-24T21:40:36+00:00",
	"remoteAddr": "10.0.1.4",
	"user": "--",
	"app": "index",
	"method": "GET",
	"url": "/",
	"message": {
		"Exception": "OC\\DB\\Exceptions\\DbalException",
		"Message": "Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] FATAL:  password authentication failed for user \"nextcloud\"",
		"Code": 7,
		"Trace": [{
			"file": "/var/www/html/lib/private/DB/ConnectionAdapter.php",
			"line": 59,
			"function": "wrap",
			"class": "OC\\DB\\Exceptions\\DbalException",
			"type": "::",
			"args": [{
				"__class__": "Doctrine\\DBAL\\Exception"
			}]
		}, {
			"file": "/var/www/html/lib/private/legacy/OC_DB.php",
			"line": 72,
			"function": "prepare",
			"class": "OC\\DB\\ConnectionAdapter",
			"type": "->",
			"args": ["SHOW SERVER_VERSION", null, null]
		}, {
			"file": "/var/www/html/lib/private/legacy/OC_DB.php",
			"line": 145,
			"function": "prepare",
			"class": "OC_DB",
			"type": "::",
			"args": ["SHOW SERVER_VERSION", null, null]
		}, {
			"file": "/var/www/html/lib/private/legacy/OC_Util.php",
			"line": 989,
			"function": "executeAudited",
			"class": "OC_DB",
			"type": "::",
			"args": [{
				"sql": "SHOW SERVER_VERSION",
				"limit": null,
				"offset": null
			}]
		}, {
			"file": "/var/www/html/lib/private/legacy/OC_Util.php",
			"line": 969,
			"function": "checkDatabaseVersion",
			"class": "OC_Util",
			"type": "::",
			"args": []
		}, {
			"file": "/var/www/html/lib/base.php",
			"line": 650,
			"function": "checkServer",
			"class": "OC_Util",
			"type": "::",
			"args": [{
				"__class__": "OC\\SystemConfig"
			}]
		}, {
			"file": "/var/www/html/lib/base.php",
			"line": 1076,
			"function": "init",
			"class": "OC",
			"type": "::",
			"args": []
		}, {
			"file": "/var/www/html/index.php",
			"line": 35,
			"args": ["/var/www/html/lib/base.php"],
			"function": "require_once"
		}],
		"File": "/var/www/html/lib/private/DB/Exceptions/DbalException.php",
		"Line": 70,
		"Previous": {
			"Exception": "Doctrine\\DBAL\\Exception",
			"Message": "Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] FATAL:  password authentication failed for user \"nextcloud\"",
			"Code": 7,
			"Trace": [{
				"file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
				"line": 1486,
				"function": "connect",
				"class": "OC\\DB\\Connection",
				"type": "->",
				"args": []
			}, {
				"file": "/var/www/html/3rdparty/doctrine/dbal/src/Statement.php",
				"line": 71,
				"function": "getWrappedConnection",
				"class": "Doctrine\\DBAL\\Connection",
				"type": "->",
				"args": []
			}, {
				"file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
				"line": 989,
				"function": "__construct",
				"class": "Doctrine\\DBAL\\Statement",
				"type": "->",
				"args": ["SHOW SERVER_VERSION", {
					"__class__": "OC\\DB\\Connection"
				}]
			}, {
				"file": "/var/www/html/lib/private/DB/Connection.php",
				"line": 204,
				"function": "prepare",
				"class": "Doctrine\\DBAL\\Connection",
				"type": "->",
				"args": ["SHOW SERVER_VERSION"]
			}, {
				"file": "/var/www/html/lib/private/DB/ConnectionAdapter.php",
				"line": 56,
				"function": "prepare",
				"class": "OC\\DB\\Connection",
				"type": "->",
				"args": ["SHOW SERVER_VERSION", null, null]
			}, {
				"file": "/var/www/html/lib/private/legacy/OC_DB.php",
				"line": 72,
				"function": "prepare",
				"class": "OC\\DB\\ConnectionAdapter",
				"type": "->",
				"args": ["SHOW SERVER_VERSION", null, null]
			}, {
				"file": "/var/www/html/lib/private/legacy/OC_DB.php",
				"line": 145,
				"function": "prepare",
				"class": "OC_DB",
				"type": "::",
				"args": ["SHOW SERVER_VERSION", null, null]
			}, {
				"file": "/var/www/html/lib/private/legacy/OC_Util.php",
				"line": 989,
				"function": "executeAudited",
				"class": "OC_DB",
				"type": "::",
				"args": [{
					"sql": "SHOW SERVER_VERSION",
					"limit": null,
					"offset": null
				}]
			}, {
				"file": "/var/www/html/lib/private/legacy/OC_Util.php",
				"line": 969,
				"function": "checkDatabaseVersion",
				"class": "OC_Util",
				"type": "::",
				"args": []
			}, {
				"file": "/var/www/html/lib/base.php",
				"line": 650,
				"function": "checkServer",
				"class": "OC_Util",
				"type": "::",
				"args": [{
					"__class__": "OC\\SystemConfig"
				}]
			}, {
				"file": "/var/www/html/lib/base.php",
				"line": 1076,
				"function": "init",
				"class": "OC",
				"type": "::",
				"args": []
			}, {
				"file": "/var/www/html/index.php",
				"line": 35,
				"args": ["/var/www/html/lib/base.php"],
				"function": "require_once"
			}],
			"File": "/var/www/html/lib/private/DB/Connection.php",
			"Line": 85
		},
		"CustomMessage": "--"
	},
	"userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0",
	"version": "21.0.1.1"
}

I (actually, multiple people) have been working at this for over a month but haven’t been able to get anywhere. Any help would be appreciated!

1 Like

do you want to test my playbook with your password?

you have to follow the readme and put your password here:

and update the postgres version here:

or share your docker-compose file so some could test your setup.

p.s.: if a given db password doesn’t work in my playbook (no sure if i ever test this), you change the length of the random password here:

1 Like

And how have you done that exactly? I ask because if “nextcloud-postgres” is the name of a container in Docker-compose, this will be resolved by Docker to the backend IP of the container and may not resolve quite as you expect.

Also, have you tried without the port or by using the wizard instead of setting variables? The documentation at Docker Hub doesn’t say whether it takes a port number with that variable.

@etnguyen03 using your password in my playbook fails:

TASK [nextcloud_config : first setup nextcloud] *****************************************************************************************************************************************
Tuesday 27 April 2021  08:17:31 +0000 (0:00:00.035)       0:02:02.308 ********* 
fatal: [localhost]: FAILED! => changed=true 
  cmd: |-
    docker exec --user www-data nextcloud php occ  maintenance:install  --database pgsql --database-host nextcloud-db --database-name nextcloud  --database-user nextcloud --database-pass gq48CHM2QVQ9VV8YrMMLDrehpHKx5U39jwFrVmYMxczXhA9PPeApVqySPDMQE9k2aqCAKhnbRFWezZBnarG99jzpJHPhaRvJy5A7  --admin-user admin --admin-pass C3dL3uaksJexM3YHt0RItuzkPnWvCVlY --data-dir /var/nc-data
  delta: '0:00:00.528918'
  end: '2021-04-27 08:17:32.419815'
  msg: non-zero return code
  rc: 1
  start: '2021-04-27 08:17:31.890897'
  stderr: ''
  stderr_lines: <omitted>
  stdout: |-
    PostgreSQL username and/or password not valid
     -> You need to enter details of an existing account.

reducing the length of your password to gq48CHM2QVQ9VV8YrMMLDrehpHKx5U39jwFrVmYMxczXhA the task works fine:

TASK [nextcloud_config : first setup nextcloud] *****************************************************************************************************************************************
Tuesday 27 April 2021  09:54:51 +0000 (0:00:00.030)       0:01:00.088 ********* 
changed: [localhost]

and I got a running nextcloud instance.

1 Like

Hmm this worked. Thank you!

(I tried a shorter password, but that didn’t work when I tried it earlier. I guess now it worked?)