FSchaefer
FSchaefer

Reputation: 1

connect to dockerized sql from host: Access denied

I'm sorry to open one more of those 'can't connect to my database' questions, but after searching for hours I just don't get it.

I want a dockerized database to be used by the (non dockerized) invoicePlane app.

So I'm using the following docker-compose.yml

version: '2'

services:
  db:
      image: mariadb:latest 
      #also tried mysql:latest
      restart: always
      environment:
          MYSQL_DATABASE: 'invoiceplane_db'
          MYSQL_USER: 'invoiceplane'
          MYSQL_PASSWORD: 'pass1'
          MYSQL_ROOT_PASSWORD: 'pass0'
      expose:
          - '3306'
      volumes:
          myserver/path:/var/lib/mysql
volumes:
    invoiceplane-db:

It starts with sudo docker-compose -f docker-compose.yml up

From inside the container, everything works fine. I can connect, e.g. via mysql -uroot -ppass0, and see

+--------------+-----------+
| User         | Host      |
+--------------+-----------+
| invoiceplane | %         |
| root         | %         |
| root         | localhost |
+--------------+-----------+
3 rows in set (0.004 sec)

Now I want to access the db from the host, trying

mysql invoiceplane_db_1:3306 -uroot -ppass0

where invoiceplane_db_1 is the container's name.

but I'm always getting:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Through my websearch I gained the impression that this may have to do with the bind-address in the /etc/mysql/my.cnf of the container, which was stated here, for example. But I was not able to get it right. Initially, the parameter was commented out. I set it to bind-address = 127.0.0.1 and restarted the container. It did not help.

Am I missing something here?

Upvotes: 0

Views: 263

Answers (1)

Lucas Campos
Lucas Campos

Reputation: 1920

This is my working docker-composer for mariadb:

db:
  image: mariadb:10.4
  ports:
    - "3306:3306"
  volumes:
    - db-storage:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: root-pass
    MYSQL_USER: my-user
    MYSQL_PASSWORD: my-user-pass
    MYSQL_DATABASE: my-database

From the looks of it, seems like you are missing the port mapping: 3306:3306

Upvotes: 1

Related Questions