0

This is my docker-compose.yml file:

version: "3.9"

services:
  db:
    image: mariadb:10.5
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: "mypassword"
      MARIADB_DATABASE: "mydb"
      MARIADB_USER: "myuser"
      MARIADB_PASSWORD: "mypassword"
      MYSQL_ROOT_PASSWORD: "mypassword"
      MYSQL_DATABASE: "mydb"
      MYSQL_USER: "myuser"
      MYSQL_PASSWORD: "mypassword"
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 10s
      retries: 10

This is how I build and start my container

docker-compose -f docker-compose.yml up --build -d

After MariaDB started I try to connect to the database inside the container

docker exec -it CONTAINERID /bin/bash
root@a88f9980d7f6:/# mariadb -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Any idea why this is not working for me?

System informations:

Docker version 20.10.17, build 100c701
Docker Compose version v2.6.1
Linux dev 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux
Debian GNU/Linux 10 (buster)
Philipp S.
  • 827
  • 17
  • 41
  • i just copy pasted the current docker-compose file and ran it, i can login... – Farhad Farahi Aug 04 '22 at 15:54
  • Which docker version and docker-compose version do you run? Can you tell me which Linux kernel and operating system you use? – Philipp S. Aug 04 '22 at 15:58
  • ```mariadb -u root -pmypassword``` this could help as you can see the password (in case of typo). Im using linux `5.18.14-1-MANJARO` docker version `20.10.17` same docker-compose version as you – Farhad Farahi Aug 04 '22 at 16:05
  • hm. I tried it on a differnt machine and it worked directly. How do you delete/rebuild a container. Maybe my approach is not correct. – Philipp S. Aug 04 '22 at 16:06
  • `docker-compose down` then you can do `docker rmi mariadb:10.5` to remove the image and do `docker-compose up -d` please note you dont need `--build` as you are referencing an image in your docker-compose.yml – Farhad Farahi Aug 04 '22 at 16:08
  • Thank you. I used `docker system prune` and thought this will delete everything. Now it works :) – Philipp S. Aug 04 '22 at 16:14
  • Note a [/usr/local/bin/healthcheck.sh](https://github.com/MariaDB/mariadb-docker/blob/master/10.5/healthcheck.sh). Checking without `--protocol tcp` can result in it appearing active too early while its still initializing. `MYSQL_*` env names are ignored when `MARIADB_*` equivalents exist. I can't see a reason for the password to not be set, unless the environment was changed after the volume was initialized. – danblack Aug 05 '22 at 01:30

1 Answers1

2

mariadb -u root -pmypassword just to make sure you are not having a typo. This could put password in the terminal history (not secure)

Could also be an issue with the image.

docker-compose down then you can do docker rmi mariadb:10.5 to remove the image and do docker-compose up -d please note you dont need --build as you are referencing an image in your docker-compose.yml

Alternatively you can do docker system prune BUT THIS WILL REMOVE all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes. USE WITH CAUTION.

Farhad Farahi
  • 35,528
  • 7
  • 73
  • 70