MariaDB Docker Access denied for user '--password='@'localhost'
by Sid Elkins
The Error
I stumbled across this error message within my MariaDB Docker container logs when trying to initialize using the following docker-compose file (modified from the Vikunja Docs):
services:
vikunja:
image: vikunja/vikunja
environment:
VIKUNJA_SERVICE_PUBLICURL: http://<the public ip or host where vikunja is reachable>
VIKUNJA_DATABASE_HOST: db
VIKUNJA_DATABASE_PASSWORD: changeme
VIKUNJA_DATABASE_TYPE: mysql
VIKUNJA_DATABASE_USER: vikunja
VIKUNJA_DATABASE_DATABASE: vikunja
VIKUNJA_SERVICE_JWTSECRET: <a super secure random secret>
ports:
- 3456:3456
volumes:
- ./files:/app/vikunja/files
depends_on:
db:
condition: service_healthy
restart: unless-stopped
db:
image: mariadb:10
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
environment:
MARIADB_ROOT_PASSWORD: supersecret
MARIADB_USER: vikunja
MARIADB_PASSWORD: changeme
MARIADB_DATABASE: vikunja
volumes:
- ./db:/var/lib/mysql
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"]
interval: 2s
start_period: 30s
I Googled the message and found nothing. It’s a very odd message, and while I haven’t looked into the Dockerfile, I think a missing environment variable is causing the --password
flag to be passed into the --user
flag.
So I’m writing this to show how to fix it in case anybody else has this issue.
The Fix
Notice that I updated the environment variable to use MARIADB
instead of MYSQL
, as this is how it is used in the MariaDB docs.
The healthcheck
on the MariaDB container attempts to ping the container with $$MYSQL_USER
and $$MYSQL_PASSWORD
, which is the cause of this issue.
So either update to $$MARIADB_USER
and $$MARIADB_PASSWORD
, or remove the healthcheck
, and it should work as intended.