root issue = the main issue
Just tested on my machine
Installed the mariadb addon (if it starts with no data in its config folder, it pops open the settings for password entry)
Entered a root password, along with a db name, user name and user password.
Installed nextcloud, didn't change any settings.
Waited for both to be started up and gave it another minute (watched the logs until services were ready for both)
Then I accessed the nextcloud gui on port 443 (https), put in a user and password, selected mysql/mariadb, entered the db and user details and for address, entered "mariadb:3306". Also unchecked the box for installing recommended apps. It connected fine and was set up within a minute or so (may take a few minutes on slower hardware).
When I exec into nextcloud, I can ping "mariadb" successfully:
# docker exec -it nextcloud ping mariadb
PING mariadb (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.119 ms
64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.094 ms
64 bytes from 172.19.0.2: seq=2 ttl=64 time=0.121 ms
^C
--- mariadb ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.094/0.111/0.121 ms
The /etc/resolv.conf in nextcloud contains the following:
# docker exec -it nextcloud cat /etc/resolv.conf
search localdomain
nameserver 127.0.0.11
options ndots:0
So really, out of the box, it should just work.