Host 'n.n.n.n' is not allowed to connect to this MariaDB server

With the following docker-compose.yml file I’m able to create 3 containers, a webserver with PHP, a MariaDB server and a phpMyAdmin server:

services:
  php-custom:
    build: .
    image: php-custom
    container_name: php-custom
    ports:
      - 4444:80
    volumes:
      - ./html:/var/www/html

  db:
    image: mariadb:latest
    container_name: mariadb
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: password
    volumes:
      - ./db:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    restart: always
    ports:
      - 8080:80
    environment:
      - PMA_HOST=db
      - PMA_POST=3306

When I try to login to either phpMyAdmin or using PHP, I get an error saying: Host ‘172.25.0.2’ is not allowed to connect to this MariaDB server in /var/www/html/index.php

I have tried numerous things, but this error keeps coming. What I want is to allow both php-custom and phpmyadmin to be able to connect to db. I have also tried MySQL, but can’t seem to get this running where MariaDB was up in minutes.

What am I overlooking here? I’m running Docker (or Container Manager) on Synology BTW.

I don’t know where this MARIADB_HOST variable is coming from. I don’T see it in the image description
https://hub.docker.com/_/mariadb

What is the exact error message? Does it really say that the host is not alowed and not that the user is not allowed like user@172.25.0.2?

You need to create a user that is allowed to access from anywhere like: user@'%'

This is also linked in the image description:

There is no MARIADB_HOST but there is a MARIADB_ROOT_HOST if you wanted to access it with the root user.

I added the following environment variables, waited a long, long, long time and now all of a sudden I’m able to login as root… I’m going crazy. Delete the user “user”, but I’m assuming it will return on my next rebuild. Strange.

MYSQL_DATABASE: mydatabase
MYSQL_USER: user
MYSQL_PASSWORD: password

Guess it’s even more strange to have your root pass in a yml file?

It doesn’t have to be in the yaml file, you can save it in a .env file and pass it like:

MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD

And that password is required only when you first start the server. You can remove the variable later. After recreating (docker compose down and docker compose up again) the container the environment variable willl disappear also from the container.

Yes maybe, but that’s all the same to me. And what if I need to recreate the container, I still need to insert it. But then again, it’s probably the same as having the password in my PHP code for connecting.

I’ll have a look at MARIADB_PASSWORD_HASH then at least it’s hashed. But can’t directly find a lot of info on the subject.

Funny thing: I just rebuilt everything without the extra environment variables and now I’m able to login. But if I have to wait this long every time I have to rebuild… dang.