172.18.0.3 app container docker IP address is not allowed to connect to this MariaDB

Hi,

I have been trying to get access to MariaDB through docker. While I am able to access MariaDB within my AWS Ubuntu instance in AWS Lightsail through the following commands:
mysql -h <ip-address where database is hosted> -p -u username database

However, when I load the page on the website IP address I get the following error:
** ‘172.18.0.3 is not allowed to connect to this MariaDB Server’**.
This is my docker-compose file:

version: '3.7'

services:
    app:
        restart: always
        build: ./app
        ports:
            - "8501:8501"
        env_file:
            - .env
        command: streamlit run Main.py
        networks:
            - streamlit_network

    mariadb:
        image: mariadb:10.5.17
        ports:
             - "3306:3306"
        volumes:
            - db_data:/var/lib/mysql
            - db_conf:/etc/mysql/conf.d
        environment:
              MYSQL_ROOT_PASSWORD: "root"
              MYSQL_DATABASE: "db"
              MYSQL_USER: "user"
              MYSQL_PASSWORD: "password"
        networks:
            - streamlit_network
    nginx:
        restart: always
        build: ./nginx
        ports:
            - "80:80"
        depends_on:
            - app
            - mariadb
        networks:
           - streamlit_network
volumes:
    db_data:
    db_conf:
networks:
    streamlit_network:
        driver: bridge

I tried removing the network part but I get the same error. I cannot use host mode in network as I need the port bindings for the web page to even load per the configuration.

This is the .env file:

host="mariadb"
user="user"
password="password"
database="db"
port="3306"

When I run this command:
for s in docker-compose ps -q; do echo ip of docker inspect -f “{{.Name}}” $sisdocker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ $s; done

I get that this IP address: 172.18.0.3 corresponds to app here. Any pointers on this ? Thanks in advance.

I don’t work with databases recently, but MariaDB probably has a default access rule so the user can access the database from specific hosts. When you try to access the database from the AWS instance, then MariaDB will see that you are from the IP address of that instance. When you try it from the MariaDB container, it will see that it is coming from localhost (or its own IP address, I don’t remember). When you try it from an other container, it will se the IP of that container. If that network is not allowed for user, you will not be able to access the database.

When I worked with MySQL, a user looked like this: myuser@localhost or myuser@192.168.1..4 or myuser@% where % meant “from anywhere”. MySQL also had other rules not depending on the username. I can’t tell you the solution, but this is what you need to look for. Try to list the existing users with an admin user.

1 Like