A container that is running is not yet a database that accepts queries. The official MariaDB image ships a script that checks the real thing, so you don’t need a hand-made mysqladmin line.
services:
db:
image: mariadb:10.11
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 15s
retries: 6
--connect checks that the server accepts a TCP connection, which only happens once the entrypoint has finished its setup. --innodb_initialized checks that InnoDB crash recovery is done. The script’s own comments recommend combining the two, because the InnoDB test alone can pass too early during the first start.
It logs in as a dedicated healthcheck user that the entrypoint creates, with its credentials in .my-healthcheck.cnf in the data directory. So there’s no root password in your compose file, which is the part I like most.
The catch is that the user only exists for data directories made by a recent image. An old volume has no .my-healthcheck.cnf, and the check keeps failing. Setting MARIADB_AUTO_UPGRADE=1 once makes the entrypoint create it. Run docker exec db healthcheck.sh --connect by hand and check the exit code when the status stays unhealthy.
Further reading: Using healthcheck.sh